Skip to content

Commit 557fd49

Browse files
committed
feat: Enable root-level typedoc generation for the project.
- All local types have been pulled out to the project directory. - Packages moved to /packages/@css-blocks for module name generation. - typedoc.js configuration file added. - packages/css-blocks => packages/@css-blocks/core - packages/webpack-plugin => packages/@css-blocks/webpack. - packages/glimmer-templates => packages/@css-blocks/glimmer. - packages/runtime/src/runtime.ts => packages/@css-blocks/runtime/src/index.ts. - yarn run docs will generate a typedoc site at /docs. - TODO: Uses pre-built forked version of typedoc-plugin-external-module-map. Remove when merged.
1 parent 5217971 commit 557fd49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+404
-90
lines changed

packages/@css-blocks/broccoli/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"author": "Adam Miller <[email protected]>",
77
"license": "MIT",
88
"keywords": [
9-
"css-blocks",
9+
"@css-blocks/core",
1010
"css blocks",
1111
"broccoli-plugin"
1212
],
@@ -46,4 +46,4 @@
4646
"recursive-readdir": "^2.2.2",
4747
"walk-sync": "^0.3.2"
4848
}
49-
}
49+
}

packages/@css-blocks/broccoli/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class BroccoliCSSBlocks extends BroccoliPlugin {
9292

9393
// Run optimization and compute StyleMapping.
9494
let optimized = await optimizer.optimize(this.output);
95-
let styleMapping = new StyleMapping(optimized.styleMapping, blocks, options, this.analyzer.analyses());
95+
let styleMapping = new StyleMapping<keyof TemplateTypes>(optimized.styleMapping, blocks, options, this.analyzer.analyses());
9696

9797
// Attach all computed data to our magic shared memory transport object...
9898
this.transport.mapping = styleMapping;

packages/@css-blocks/core/src/Analyzer/Analysis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// tslint:disable-next-line:no-unused-variable Imported for Documentation link
22
import {
3+
isSourcePosition,
34
POSITION_UNKNOWN,
45
SourceLocation,
56
SourcePosition,
6-
isSourcePosition,
77
} from "@opticss/element-analysis";
88
import {
99
SerializedTemplateInfo,

packages/@css-blocks/core/src/Analyzer/Analyzer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { BlockFactory } from "../BlockParser";
1010
import { Block, Style } from "../BlockTree";
1111
import {
1212
Options,
13-
ResolvedConfiguration,
1413
resolveConfiguration,
14+
ResolvedConfiguration,
1515
} from "../configuration";
1616

1717
import { Analysis, SerializedAnalysis } from "./Analysis";

packages/@css-blocks/core/src/Analyzer/ElementAnalysis.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import {
44
AttributeValueChoiceOption,
55
AttributeValueSet,
66
AttributeValueSetItem,
7+
attrValues,
78
Element,
9+
isConstant,
810
POSITION_UNKNOWN,
911
SourceLocation,
1012
Tagname,
1113
ValueAbsent,
1214
ValueConstant,
13-
attrValues,
14-
isConstant,
1515
} from "@opticss/element-analysis";
1616
import {
1717
MultiMap,
@@ -21,13 +21,13 @@ import {
2121
} from "@opticss/util";
2222

2323
import {
24-
AttrValue,
2524
Attribute,
25+
AttrValue,
2626
Block,
2727
BlockClass,
28-
Style,
2928
isAttrValue,
3029
isBlockClass,
30+
Style,
3131
} from "../BlockTree";
3232
import {
3333
ResolvedConfiguration,

packages/@css-blocks/core/src/Analyzer/validations/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import * as errors from "../../errors";
55
import { Analysis } from "../Analysis";
66
import { ElementAnalysis } from "../ElementAnalysis";
77

8+
import { Validator } from "./Validator";
89
import { attributeGroupValidator } from "./attribute-group-validator";
910
import { attributeParentValidator } from "./attribute-parent-validator";
1011
import { classPairsValidator } from "./class-pairs-validator";
1112
import { propertyConflictValidator } from "./property-conflict-validator";
1213
import { rootClassValidator } from "./root-class-validator";
13-
import { Validator } from "./Validator";
1414

1515
export * from "./class-pairs-validator";
1616
export * from "./root-class-validator";

packages/@css-blocks/core/src/Analyzer/validations/property-conflict-validator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MultiMap, TwoKeyMultiMap, objectValues } from "@opticss/util";
1+
import { MultiMap, objectValues, TwoKeyMultiMap } from "@opticss/util";
22
import * as propParser from "css-property-parser";
33
import { postcss } from "opticss";
44

packages/@css-blocks/core/src/BlockCompiler/ConflictResolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { CompoundSelector, ParsedSelector, parseSelector, postcss, postcssSelect
44
import { getBlockNode } from "../BlockParser";
55
import { RESOLVE_RE } from "../BlockSyntax";
66
import { Block, Style } from "../BlockTree";
7+
import { SourceLocation, sourceLocation } from "../SourceLocation";
78
import { ResolvedConfiguration } from "../configuration";
89
import * as errors from "../errors";
910
import { QueryKeySelector } from "../query";
10-
import { SourceLocation, sourceLocation } from "../SourceLocation";
1111

1212
import { Conflicts, detectConflicts } from "./conflictDetection";
1313

packages/@css-blocks/core/src/BlockCompiler/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import {
66
BLOCK_DEBUG,
77
BLOCK_PROP_NAMES_RE,
88
BLOCK_REFERENCE,
9-
ROOT_CLASS,
109
parseBlockDebug,
10+
ROOT_CLASS,
1111
} from "../BlockSyntax";
1212
import { Block } from "../BlockTree";
1313
import {
1414
Options,
15-
ResolvedConfiguration,
1615
resolveConfiguration,
16+
ResolvedConfiguration,
1717
} from "../configuration";
1818

1919
import { ConflictResolver } from "./ConflictResolver";

packages/@css-blocks/core/src/BlockParser/BlockFactory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import * as path from "path";
55
import { RawSourceMap } from "source-map";
66

77
import { Block } from "../BlockTree";
8-
import { Options, ResolvedConfiguration, resolveConfiguration } from "../configuration";
8+
import { Options, resolveConfiguration, ResolvedConfiguration } from "../configuration";
99
import { FileIdentifier, ImportedFile, Importer } from "../importing";
1010
import { PromiseQueue } from "../util/PromiseQueue";
1111

1212
import { BlockParser, ParsedSource } from "./BlockParser";
13-
import { Preprocessor, Preprocessors, ProcessedFile, Syntax, annotateCssContentWithSourceMap, syntaxName } from "./preprocessing";
13+
import { annotateCssContentWithSourceMap, Preprocessor, Preprocessors, ProcessedFile, Syntax, syntaxName } from "./preprocessing";
1414

1515
const debug = debugGenerator("css-blocks:BlockFactory");
1616

packages/@css-blocks/core/src/BlockParser/BlockParser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { postcss } from "opticss";
22

33
import { Block } from "../BlockTree";
4-
import { Options, ResolvedConfiguration, resolveConfiguration } from "../configuration";
4+
import { Options, resolveConfiguration, ResolvedConfiguration } from "../configuration";
55
import * as errors from "../errors";
66
import { FileIdentifier } from "../importing";
77

packages/@css-blocks/core/src/BlockParser/features/assert-foreign-global-attribute.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { postcss } from "opticss";
22

33
import { Block } from "../../BlockTree";
4-
import * as errors from "../../errors";
54
import { selectorSourceLocation as loc } from "../../SourceLocation";
5+
import * as errors from "../../errors";
66
import {
77
BlockType,
88
getBlockNode,

packages/@css-blocks/core/src/BlockParser/features/construct-block.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { assertNever } from "@opticss/util";
22
import { CompoundSelector, ParsedSelector, postcss, postcssSelectorParser as selectorParser } from "opticss";
33

44
import { Block, Style } from "../../BlockTree";
5-
import * as errors from "../../errors";
65
import { selectorSourceLocation as loc, sourceLocation } from "../../SourceLocation";
6+
import * as errors from "../../errors";
77
import {
88
BlockNodeAndType,
99
BlockType,
10-
NodeAndType,
1110
blockTypeName,
1211
getBlockNode,
1312
isAttributeNode,
1413
isClassLevelObject,
1514
isClassNode,
1615
isRootLevelObject,
1716
isRootNode,
17+
NodeAndType,
1818
toAttrToken,
1919
} from "../block-intermediates";
2020

packages/@css-blocks/core/src/BlockParser/features/disallow-important.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { postcss } from "opticss";
22

3-
import * as errors from "../../errors";
43
import { sourceLocation as loc } from "../../SourceLocation";
4+
import * as errors from "../../errors";
55

66
export async function disallowImportant(root: postcss.Root, file: string): Promise<postcss.Root> {
77
root.walkDecls((decl) => {

packages/@css-blocks/core/src/BlockParser/features/discover-name.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { postcss } from "opticss";
22

33
import { BLOCK_NAME, CLASS_NAME_IDENT } from "../../BlockSyntax";
4-
import * as errors from "../../errors";
54
import { sourceLocation } from "../../SourceLocation";
5+
import * as errors from "../../errors";
66

77
export async function discoverName(root: postcss.Root, defaultName: string, file: string): Promise<string> {
88

packages/@css-blocks/core/src/BlockParser/features/extend-block.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { postcss } from "opticss";
22

33
import { EXTENDS } from "../../BlockSyntax";
44
import { Block } from "../../BlockTree";
5-
import * as errors from "../../errors";
65
import { sourceLocation } from "../../SourceLocation";
6+
import * as errors from "../../errors";
77

88
/**
99
* For each `extends` property found in the passed ruleset, set the block's base

packages/@css-blocks/core/src/BlockParser/features/global-attributes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { parseSelector, postcss, postcssSelectorParser as selectorParser } from
22

33
import { BLOCK_GLOBAL } from "../../BlockSyntax";
44
import { Block } from "../../BlockTree";
5-
import * as errors from "../../errors";
65
import { sourceLocation as loc } from "../../SourceLocation";
6+
import * as errors from "../../errors";
77
import { toAttrToken } from "../block-intermediates";
88

99
export async function globalAttributes(root: postcss.Root, block: Block, file: string): Promise<Block> {

packages/@css-blocks/core/src/BlockParser/features/implement-block.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { postcss } from "opticss";
22

33
import { IMPLEMENTS } from "../../BlockSyntax";
44
import { Block } from "../../BlockTree";
5-
import * as errors from "../../errors";
65
import { sourceLocation } from "../../SourceLocation";
6+
import * as errors from "../../errors";
77

88
/**
99
* For each `implements` property found in the passed ruleset, track the foreign

packages/@css-blocks/core/src/BlockParser/features/resolve-references.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { postcss } from "opticss";
33

44
import { BLOCK_REFERENCE, CLASS_NAME_IDENT } from "../../BlockSyntax";
55
import { Block } from "../../BlockTree";
6-
import * as errors from "../../errors";
76
import { sourceLocation } from "../../SourceLocation";
7+
import * as errors from "../../errors";
88
import { BlockFactory } from "../index";
99

1010
/**

packages/@css-blocks/core/src/BlockSyntax/parseBlockDebug.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { postcss } from "opticss";
22

33
import { Block } from "../BlockTree";
4-
import * as errors from "../errors";
54
import { sourceLocation } from "../SourceLocation";
5+
import * as errors from "../errors";
66

77
export type DebugChannel = "comment" | "stderr" | "stdout";
88

packages/@css-blocks/core/src/BlockTree/Attribute.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ValueAbsent,
77
ValueConstant,
88
} from "@opticss/element-analysis";
9-
import { ObjectDictionary, assertNever } from "@opticss/util";
9+
import { assertNever, ObjectDictionary } from "@opticss/util";
1010

1111
import { ATTR_PRESENT, IAttrToken as AttrToken } from "../BlockSyntax";
1212
import { OutputMode, ResolvedConfiguration } from "../configuration";

packages/@css-blocks/core/src/BlockTree/Block.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MultiMap, ObjectDictionary, assertNever } from "@opticss/util";
1+
import { assertNever, MultiMap, ObjectDictionary } from "@opticss/util";
22
import { whatever } from "@opticss/util";
33
import {
44
CompoundSelector,
@@ -10,16 +10,16 @@ import {
1010

1111
import {
1212
BlockType,
13-
NodeAndType,
1413
isAttributeNode,
1514
isClassNode,
15+
NodeAndType,
1616
} from "../BlockParser";
1717
import { isRootNode, toAttrToken } from "../BlockParser";
1818
import { BlockPath, CLASS_NAME_IDENT, ROOT_CLASS } from "../BlockSyntax";
19+
import { SourceLocation } from "../SourceLocation";
1920
import { ResolvedConfiguration } from "../configuration";
2021
import { CssBlockError, InvalidBlockSyntax } from "../errors";
2122
import { FileIdentifier } from "../importing";
22-
import { SourceLocation } from "../SourceLocation";
2323

2424
import { BlockClass } from "./BlockClass";
2525
import { Inheritable } from "./Inheritable";

packages/@css-blocks/core/src/BlockTree/BlockClass.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { ATTR_PRESENT, IAttrToken as AttrToken, ROOT_CLASS } from "../BlockSynta
66
import { BlockPath } from "../BlockSyntax";
77
import { OutputMode, ResolvedConfiguration } from "../configuration";
88

9-
import { Attribute } from "./Attribute";
109
import { AttrValue } from "./AttrValue";
10+
import { Attribute } from "./Attribute";
1111
import { Block } from "./Block";
1212
import { RulesetContainer } from "./RulesetContainer";
1313
import { Style } from "./Style";

packages/@css-blocks/core/src/BlockTree/RulesetContainer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import * as propParser from "css-property-parser";
1111
import { ParsedSelector, postcss } from "opticss";
1212

1313
import { BLOCK_PROP_NAMES, RESOLVE_RE, SELF_SELECTOR } from "../BlockSyntax";
14-
import { InvalidBlockSyntax } from "../errors";
1514
import { sourceLocation } from "../SourceLocation";
15+
import { InvalidBlockSyntax } from "../errors";
1616

17-
import { Styles, isStyle } from "./Styles";
17+
import { isStyle, Styles } from "./Styles";
1818
export { Styles, BlockClass, AttrValue } from "./Styles";
1919

2020
// Convenience types to help our code read better.
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { postcss } from "opticss";
2+
3+
import { BlockCompiler } from "./BlockCompiler";
4+
import { BlockFactory } from "./BlockParser";
5+
import { Options, resolveConfiguration, ResolvedConfiguration } from "./configuration";
6+
import * as errors from "./errors";
7+
8+
/**
9+
* CSS Blocks PostCSS plugin.
10+
*/
11+
export class Plugin {
12+
private config: ResolvedConfiguration;
13+
private postcss: typeof postcss;
14+
15+
/**
16+
* @param postcssImpl PostCSS instance to use
17+
* @param opts Optional plugin config options
18+
*/
19+
constructor(postcssImpl: typeof postcss, opts?: Options) {
20+
this.config = resolveConfiguration(opts);
21+
this.postcss = postcssImpl;
22+
}
23+
24+
/**
25+
* Main processing entrypoint for PostCSS Plugin
26+
* @param root PostCSS AST
27+
* @param result Provides the result of the PostCSS transformations
28+
*/
29+
public process(root: postcss.Root, result: postcss.Result) {
30+
31+
// Fetch the CSS source file path. Throw if not present.
32+
let sourceFile: string;
33+
if (result && result.opts && result.opts.from) {
34+
sourceFile = result.opts.from;
35+
} else {
36+
throw new errors.MissingSourcePath();
37+
}
38+
39+
// Fetch block name from importer
40+
let identifier = this.config.importer.identifier(null, sourceFile, this.config);
41+
let defaultName: string = this.config.importer.defaultName(identifier, this.config);
42+
let factory = new BlockFactory(this.config, this.postcss);
43+
44+
return factory.parse(root, sourceFile, defaultName).then((block) => {
45+
let compiler = new BlockCompiler(postcss, this.config);
46+
compiler.compile(block, root);
47+
});
48+
}
49+
50+
}

packages/@css-blocks/core/src/TemplateRewriter/RewriteMapping.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {
22
BooleanExpression,
3-
RewriteMapping as OptimizedMapping,
4-
SimpleAttribute,
5-
SimpleTagname,
63
isAndExpression,
74
isBooleanExpression,
85
isNotExpression,
96
isOrExpression,
107
isSimpleTagname,
8+
RewriteMapping as OptimizedMapping,
9+
SimpleAttribute,
10+
SimpleTagname,
1111
} from "@opticss/template-api";
12-
import { Maybe, ObjectDictionary, assertNever, maybe, objectValues } from "@opticss/util";
12+
import { assertNever, Maybe, maybe, ObjectDictionary, objectValues } from "@opticss/util";
1313
import { inspect } from "util";
1414

1515
import { Style } from "../BlockTree";

packages/@css-blocks/core/src/configuration/resolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Preprocessors } from "../BlockParser";
22
import {
3+
filesystemImporter,
34
Importer,
45
ImporterData,
5-
filesystemImporter,
66
} from "../importing";
77

88
import { OutputMode } from "./OutputMode";

0 commit comments

Comments
 (0)