@terrazzo/parser 0.7.3 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/index.d.ts +705 -12
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +4603 -12
  5. package/dist/index.js.map +1 -1
  6. package/package.json +11 -7
  7. package/src/build/index.ts +8 -6
  8. package/src/index.ts +76 -1
  9. package/dist/build/index.d.ts +0 -20
  10. package/dist/build/index.d.ts.map +0 -1
  11. package/dist/build/index.js +0 -166
  12. package/dist/build/index.js.map +0 -1
  13. package/dist/config.d.ts +0 -8
  14. package/dist/config.d.ts.map +0 -1
  15. package/dist/config.js +0 -290
  16. package/dist/config.js.map +0 -1
  17. package/dist/lib/code-frame.d.ts +0 -31
  18. package/dist/lib/code-frame.d.ts.map +0 -1
  19. package/dist/lib/code-frame.js +0 -108
  20. package/dist/lib/code-frame.js.map +0 -1
  21. package/dist/lint/index.d.ts +0 -12
  22. package/dist/lint/index.d.ts.map +0 -1
  23. package/dist/lint/index.js +0 -105
  24. package/dist/lint/index.js.map +0 -1
  25. package/dist/lint/plugin-core/index.d.ts +0 -13
  26. package/dist/lint/plugin-core/index.d.ts.map +0 -1
  27. package/dist/lint/plugin-core/index.js +0 -40
  28. package/dist/lint/plugin-core/index.js.map +0 -1
  29. package/dist/lint/plugin-core/lib/docs.d.ts +0 -2
  30. package/dist/lint/plugin-core/lib/docs.d.ts.map +0 -1
  31. package/dist/lint/plugin-core/lib/docs.js +0 -4
  32. package/dist/lint/plugin-core/lib/docs.js.map +0 -1
  33. package/dist/lint/plugin-core/rules/a11y-min-contrast.d.ts +0 -40
  34. package/dist/lint/plugin-core/rules/a11y-min-contrast.d.ts.map +0 -1
  35. package/dist/lint/plugin-core/rules/a11y-min-contrast.js +0 -58
  36. package/dist/lint/plugin-core/rules/a11y-min-contrast.js.map +0 -1
  37. package/dist/lint/plugin-core/rules/a11y-min-font-size.d.ts +0 -14
  38. package/dist/lint/plugin-core/rules/a11y-min-font-size.d.ts.map +0 -1
  39. package/dist/lint/plugin-core/rules/a11y-min-font-size.js +0 -45
  40. package/dist/lint/plugin-core/rules/a11y-min-font-size.js.map +0 -1
  41. package/dist/lint/plugin-core/rules/colorspace.d.ts +0 -15
  42. package/dist/lint/plugin-core/rules/colorspace.d.ts.map +0 -1
  43. package/dist/lint/plugin-core/rules/colorspace.js +0 -85
  44. package/dist/lint/plugin-core/rules/colorspace.js.map +0 -1
  45. package/dist/lint/plugin-core/rules/consistent-naming.d.ts +0 -12
  46. package/dist/lint/plugin-core/rules/consistent-naming.d.ts.map +0 -1
  47. package/dist/lint/plugin-core/rules/consistent-naming.js +0 -49
  48. package/dist/lint/plugin-core/rules/consistent-naming.js.map +0 -1
  49. package/dist/lint/plugin-core/rules/descriptions.d.ts +0 -10
  50. package/dist/lint/plugin-core/rules/descriptions.d.ts.map +0 -1
  51. package/dist/lint/plugin-core/rules/descriptions.js +0 -32
  52. package/dist/lint/plugin-core/rules/descriptions.js.map +0 -1
  53. package/dist/lint/plugin-core/rules/duplicate-values.d.ts +0 -10
  54. package/dist/lint/plugin-core/rules/duplicate-values.d.ts.map +0 -1
  55. package/dist/lint/plugin-core/rules/duplicate-values.js +0 -65
  56. package/dist/lint/plugin-core/rules/duplicate-values.js.map +0 -1
  57. package/dist/lint/plugin-core/rules/max-gamut.d.ts +0 -15
  58. package/dist/lint/plugin-core/rules/max-gamut.d.ts.map +0 -1
  59. package/dist/lint/plugin-core/rules/max-gamut.js +0 -101
  60. package/dist/lint/plugin-core/rules/max-gamut.js.map +0 -1
  61. package/dist/lint/plugin-core/rules/required-children.d.ts +0 -19
  62. package/dist/lint/plugin-core/rules/required-children.d.ts.map +0 -1
  63. package/dist/lint/plugin-core/rules/required-children.js +0 -78
  64. package/dist/lint/plugin-core/rules/required-children.js.map +0 -1
  65. package/dist/lint/plugin-core/rules/required-modes.d.ts +0 -14
  66. package/dist/lint/plugin-core/rules/required-modes.d.ts.map +0 -1
  67. package/dist/lint/plugin-core/rules/required-modes.js +0 -52
  68. package/dist/lint/plugin-core/rules/required-modes.js.map +0 -1
  69. package/dist/lint/plugin-core/rules/required-typography-properties.d.ts +0 -11
  70. package/dist/lint/plugin-core/rules/required-typography-properties.d.ts.map +0 -1
  71. package/dist/lint/plugin-core/rules/required-typography-properties.js +0 -38
  72. package/dist/lint/plugin-core/rules/required-typography-properties.js.map +0 -1
  73. package/dist/logger.d.ts +0 -77
  74. package/dist/logger.d.ts.map +0 -1
  75. package/dist/logger.js +0 -136
  76. package/dist/logger.js.map +0 -1
  77. package/dist/parse/alias.d.ts +0 -34
  78. package/dist/parse/alias.d.ts.map +0 -1
  79. package/dist/parse/alias.js +0 -302
  80. package/dist/parse/alias.js.map +0 -1
  81. package/dist/parse/index.d.ts +0 -41
  82. package/dist/parse/index.d.ts.map +0 -1
  83. package/dist/parse/index.js +0 -273
  84. package/dist/parse/index.js.map +0 -1
  85. package/dist/parse/json.d.ts +0 -52
  86. package/dist/parse/json.d.ts.map +0 -1
  87. package/dist/parse/json.js +0 -168
  88. package/dist/parse/json.js.map +0 -1
  89. package/dist/parse/normalize.d.ts +0 -24
  90. package/dist/parse/normalize.d.ts.map +0 -1
  91. package/dist/parse/normalize.js +0 -176
  92. package/dist/parse/normalize.js.map +0 -1
  93. package/dist/parse/validate.d.ts +0 -90
  94. package/dist/parse/validate.d.ts.map +0 -1
  95. package/dist/parse/validate.js +0 -787
  96. package/dist/parse/validate.js.map +0 -1
  97. package/dist/types.d.ts +0 -265
  98. package/dist/types.d.ts.map +0 -1
  99. package/dist/types.js +0 -2
  100. package/dist/types.js.map +0 -1
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@terrazzo/parser",
3
- "version": "0.7.3",
3
+ "version": "0.8.1",
4
4
  "description": "Parser/validator for the Design Tokens Community Group (DTCG) standard.",
5
+ "license": "MIT",
5
6
  "type": "module",
6
7
  "author": {
7
8
  "name": "Drew Powers",
@@ -22,33 +23,36 @@
22
23
  "lint"
23
24
  ],
24
25
  "main": "./dist/index.js",
26
+ "exports": {
27
+ ".": "./dist/index.js",
28
+ "./package.json": "./package.json"
29
+ },
25
30
  "homepage": "https://terrazzo.app/docs/cli/api/js",
26
31
  "repository": {
27
32
  "type": "git",
28
33
  "url": "https://github.com/terrazzoapp/terrazzo.git",
29
34
  "directory": "./packages/parser/"
30
35
  },
31
- "license": "MIT",
32
36
  "dependencies": {
33
37
  "@humanwhocodes/momoa": "^3.3.8",
34
38
  "@types/babel__code-frame": "^7.0.6",
35
39
  "@types/culori": "^4.0.0",
36
40
  "culori": "^4.0.1",
37
- "is-what": "^4.1.16",
38
41
  "merge-anything": "^5.1.7",
39
42
  "picocolors": "^1.1.1",
40
43
  "scule": "^1.3.0",
41
44
  "wildcard-match": "^5.1.4",
42
- "yaml": "^2.8.0",
43
- "@terrazzo/token-tools": "^0.7.4"
45
+ "@terrazzo/token-tools": "^0.8.1"
44
46
  },
45
47
  "devDependencies": {
46
48
  "yaml-to-momoa": "^0.0.3"
47
49
  },
48
50
  "scripts": {
49
- "build": "tsc -p tsconfig.build.json",
51
+ "build": "rolldown -c && attw --profile esm-only --pack .",
50
52
  "dev": "pnpm run build --watch",
51
- "lint": "biome check .",
53
+ "lint": "pnpm --filter @terrazzo/parser run \"/^lint:(js|ts)/\"",
54
+ "lint:js": "biome check .",
55
+ "lint:ts": "tsc --noEmit",
52
56
  "test": "vitest run"
53
57
  }
54
58
  }
@@ -18,7 +18,7 @@ function validateTransformParams({
18
18
  params,
19
19
  logger,
20
20
  pluginName,
21
- }: { params: TokenTransformed; logger: Logger; pluginName: string }) {
21
+ }: { params: TokenTransformed; logger: Logger; pluginName: string }): void {
22
22
  const baseMessage: LogEntry = { group: 'plugin', label: pluginName, message: '' };
23
23
 
24
24
  // validate value is valid for SINGLE_VALUE or MULTI_VALUE
@@ -42,18 +42,20 @@ function validateTransformParams({
42
42
  }
43
43
  }
44
44
 
45
- /**
46
- * Run build stage
47
- */
45
+ /** Run build stage */
48
46
  export default async function build(
49
47
  tokens: Record<string, TokenNormalized>,
50
48
  { sources, logger = new Logger(), config }: BuildRunnerOptions,
51
- ) {
49
+ ): Promise<BuildRunnerResult> {
52
50
  const formats: Record<string, TokenTransformed[]> = {};
53
51
  const result: BuildRunnerResult = { outputFiles: [] };
54
52
 
55
53
  function getTransforms(params: TransformParams) {
56
- return (formats[params.format] ?? []).filter((token) => {
54
+ if (!params?.format) {
55
+ logger.warn({ group: 'plugin', message: '"format" missing from getTransforms(), no tokens returned.' });
56
+ return [];
57
+ }
58
+ return (formats[params.format!] ?? []).filter((token) => {
57
59
  if (params.$type) {
58
60
  if (typeof params.$type === 'string' && token.token.$type !== params.$type) {
59
61
  return false;
package/src/index.ts CHANGED
@@ -15,4 +15,79 @@ export * from './parse/index.js';
15
15
 
16
16
  export * from './types.js';
17
17
 
18
- export * from '@terrazzo/token-tools/dist/types.js';
18
+ export type {
19
+ AliasToken,
20
+ AliasValue,
21
+ BooleanToken,
22
+ BooleanTokenNormalized,
23
+ BooleanValue,
24
+ BorderToken,
25
+ BorderTokenNormalized,
26
+ BorderValue,
27
+ BorderValueNormalized,
28
+ ColorSpace,
29
+ ColorToken,
30
+ ColorTokenNormalized,
31
+ ColorValue,
32
+ ColorValueNormalized,
33
+ CubicBezierToken,
34
+ CubicBezierTokenNormalized,
35
+ CubicBezierValue,
36
+ CustomTransformOptions,
37
+ DimensionToken,
38
+ DimensionTokenNormalized,
39
+ DimensionValue,
40
+ DurationToken,
41
+ DurationTokenNormalized,
42
+ DurationValue,
43
+ FontFamilyToken,
44
+ FontFamilyTokenNormalized,
45
+ FontFamilyValue,
46
+ FontFamilyValueNormalized,
47
+ FontWeightToken,
48
+ FontWeightTokenNormalized,
49
+ FontWeightValue,
50
+ FontWeightValueNormalized,
51
+ GradientStop,
52
+ GradientStopNormalized,
53
+ GradientToken,
54
+ GradientTokenNormalized,
55
+ GradientValue,
56
+ GradientValueNormalized,
57
+ Group,
58
+ GroupCore,
59
+ GroupOrToken,
60
+ LinkToken,
61
+ LinkTokenNormalized,
62
+ LinkValue,
63
+ ModeMap,
64
+ NumberToken,
65
+ NumberTokenNormalized,
66
+ NumberValue,
67
+ ShadowToken,
68
+ ShadowTokenNormalized,
69
+ ShadowValue,
70
+ ShadowValueNormalized,
71
+ StringToken,
72
+ StringTokenNormalized,
73
+ StringValue,
74
+ StrokeStyleToken,
75
+ StrokeStyleTokenNormalized,
76
+ StrokeStyleValue,
77
+ StrokeStyleValueExpanded,
78
+ Token,
79
+ TokenCore,
80
+ TokenMode,
81
+ TokenNormalized,
82
+ TokenNormalizedCore,
83
+ TokenNormalizedSet,
84
+ TokensSet,
85
+ TransitionToken,
86
+ TransitionTokenNormalized,
87
+ TransitionValue,
88
+ TransitionValueNormalized,
89
+ TypographyToken,
90
+ TypographyTokenNormalized,
91
+ TypographyValue,
92
+ TypographyValueNormalized,
93
+ } from '@terrazzo/token-tools';
@@ -1,20 +0,0 @@
1
- import type { DocumentNode } from '@humanwhocodes/momoa';
2
- import { type TokenNormalized } from '@terrazzo/token-tools';
3
- import Logger from '../logger.js';
4
- import type { BuildRunnerResult, ConfigInit } from '../types.js';
5
- export interface BuildRunnerOptions {
6
- sources: {
7
- filename?: URL;
8
- src: string;
9
- document: DocumentNode;
10
- }[];
11
- config: ConfigInit;
12
- logger?: Logger;
13
- }
14
- export declare const SINGLE_VALUE = "SINGLE_VALUE";
15
- export declare const MULTI_VALUE = "MULTI_VALUE";
16
- /**
17
- * Run build stage
18
- */
19
- export default function build(tokens: Record<string, TokenNormalized>, { sources, logger, config }: BuildRunnerOptions): Promise<BuildRunnerResult>;
20
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,KAAK,eAAe,EAAgB,MAAM,uBAAuB,CAAC;AAE3E,OAAO,MAAyB,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAqC,MAAM,aAAa,CAAC;AAEpG,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,GAAG,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,YAAY,CAAA;KAAE,EAAE,CAAC;IACnE,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAC3C,eAAO,MAAM,WAAW,gBAAgB,CAAC;AA+BzC;;GAEG;AACH,wBAA8B,KAAK,CACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EACvC,EAAE,OAAO,EAAE,MAAqB,EAAE,MAAM,EAAE,EAAE,kBAAkB,8BAsJ/D"}
@@ -1,166 +0,0 @@
1
- import { isTokenMatch } from '@terrazzo/token-tools';
2
- import wcmatch from 'wildcard-match';
3
- import Logger, {} from '../logger.js';
4
- export const SINGLE_VALUE = 'SINGLE_VALUE';
5
- export const MULTI_VALUE = 'MULTI_VALUE';
6
- /** Validate plugin setTransform() calls for immediate feedback */
7
- function validateTransformParams({ params, logger, pluginName, }) {
8
- const baseMessage = { group: 'plugin', label: pluginName, message: '' };
9
- // validate value is valid for SINGLE_VALUE or MULTI_VALUE
10
- if (!params.value ||
11
- (typeof params.value !== 'string' && typeof params.value !== 'object') ||
12
- Array.isArray(params.value)) {
13
- logger.error({
14
- ...baseMessage,
15
- message: `setTransform() value expected string or object of strings, received ${Array.isArray(params.value) ? 'Array' : typeof params.value}`,
16
- });
17
- }
18
- if (typeof params.value === 'object' && Object.values(params.value).some((v) => typeof v !== 'string')) {
19
- logger.error({
20
- ...baseMessage,
21
- message: 'setTransform() value expected object of strings, received some non-string values',
22
- });
23
- }
24
- }
25
- /**
26
- * Run build stage
27
- */
28
- export default async function build(tokens, { sources, logger = new Logger(), config }) {
29
- const formats = {};
30
- const result = { outputFiles: [] };
31
- function getTransforms(params) {
32
- return (formats[params.format] ?? []).filter((token) => {
33
- if (params.$type) {
34
- if (typeof params.$type === 'string' && token.token.$type !== params.$type) {
35
- return false;
36
- }
37
- else if (Array.isArray(params.$type) && !params.$type.some(($type) => token.token.$type === $type)) {
38
- return false;
39
- }
40
- }
41
- if (params.id &&
42
- params.id !== '*' &&
43
- !isTokenMatch(token.token.id, Array.isArray(params.id) ? params.id : [params.id])) {
44
- return false;
45
- }
46
- if (params.mode && !wcmatch(params.mode)(token.mode)) {
47
- return false;
48
- }
49
- return true;
50
- });
51
- }
52
- // transform()
53
- let transformsLocked = false; // prevent plugins from transforming after stage has ended
54
- const startTransform = performance.now();
55
- for (const plugin of config.plugins) {
56
- if (typeof plugin.transform === 'function') {
57
- await plugin.transform({
58
- tokens,
59
- sources,
60
- getTransforms,
61
- setTransform(id, params) {
62
- if (transformsLocked) {
63
- logger.warn({
64
- message: 'Attempted to call setTransform() after transform step has completed.',
65
- group: 'plugin',
66
- label: plugin.name,
67
- });
68
- return;
69
- }
70
- const token = tokens[id];
71
- // allow `undefined` values, but remove them here
72
- const cleanValue = typeof params.value === 'string' ? params.value : { ...params.value };
73
- if (typeof cleanValue === 'object') {
74
- for (const k of Object.keys(cleanValue)) {
75
- if (cleanValue[k] === undefined) {
76
- delete cleanValue[k];
77
- }
78
- }
79
- }
80
- validateTransformParams({
81
- logger,
82
- params: { ...params, value: cleanValue },
83
- pluginName: plugin.name,
84
- });
85
- // upsert
86
- if (!formats[params.format]) {
87
- formats[params.format] = [];
88
- }
89
- const foundTokenI = formats[params.format].findIndex((t) => id === t.id &&
90
- (!params.localID || params.localID === t.localID) &&
91
- (!params.mode || params.mode === t.mode));
92
- if (foundTokenI === -1) {
93
- formats[params.format].push({
94
- ...params,
95
- id,
96
- value: cleanValue,
97
- type: typeof cleanValue === 'string' ? SINGLE_VALUE : MULTI_VALUE,
98
- mode: params.mode || '.',
99
- token: structuredClone(token),
100
- });
101
- }
102
- else {
103
- formats[params.format][foundTokenI].value = cleanValue;
104
- formats[params.format][foundTokenI].type = typeof cleanValue === 'string' ? SINGLE_VALUE : MULTI_VALUE;
105
- }
106
- },
107
- });
108
- }
109
- }
110
- transformsLocked = true;
111
- logger.debug({
112
- group: 'parser',
113
- label: 'transform',
114
- message: 'transform() step',
115
- timing: performance.now() - startTransform,
116
- });
117
- // build()
118
- const startBuild = performance.now();
119
- for (const plugin of config.plugins) {
120
- if (typeof plugin.build === 'function') {
121
- const pluginBuildStart = performance.now();
122
- await plugin.build({
123
- tokens,
124
- sources,
125
- getTransforms,
126
- outputFile(filename, contents) {
127
- const resolved = new URL(filename, config.outDir);
128
- if (result.outputFiles.some((f) => new URL(f.filename, config.outDir).href === resolved.href)) {
129
- logger.error({
130
- group: 'plugin',
131
- message: `Can’t overwrite file "${filename}"`,
132
- label: plugin.name,
133
- });
134
- }
135
- result.outputFiles.push({
136
- filename,
137
- contents,
138
- plugin: plugin.name,
139
- time: performance.now() - pluginBuildStart,
140
- });
141
- },
142
- });
143
- }
144
- }
145
- logger.debug({
146
- group: 'parser',
147
- label: 'build',
148
- message: 'build() step',
149
- timing: performance.now() - startBuild,
150
- });
151
- // buildEnd()
152
- const startBuildEnd = performance.now();
153
- for (const plugin of config.plugins) {
154
- if (typeof plugin.buildEnd === 'function') {
155
- await plugin.buildEnd({ outputFiles: structuredClone(result.outputFiles) });
156
- }
157
- }
158
- logger.debug({
159
- group: 'parser',
160
- label: 'build',
161
- message: 'buildEnd() step',
162
- timing: performance.now() - startBuildEnd,
163
- });
164
- return result;
165
- }
166
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,YAAY,EAAE,MAAM,uBAAuB,C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,CAAC,KAAK,CAAC;QACX,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,cAAc;QACvB,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,UAAU;KACvC,CAAC,CAAC;IAEH,aAAa;IACb,MAAM,aAAa,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACxC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpC,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;YAC1C,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC;IACD,MAAM,CAAC,KAAK,CAAC;QACX,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,iBAAiB;QAC1B,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,aAAa;KAC1C,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/dist/config.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { Config, ConfigInit, ConfigOptions } from './types.js';
2
- /**
3
- * Validate and normalize a config
4
- */
5
- export default function defineConfig(rawConfig: Config, { logger, cwd }?: ConfigOptions): ConfigInit;
6
- /** Merge configs */
7
- export declare function mergeConfigs(a: Config, b: Config): Config;
8
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAoB,MAAM,YAAY,CAAC;AAItF;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,SAAS,EAAE,MAAM,EACjB,EAAE,MAAqB,EAAE,GAAG,EAAE,GAAE,aAAmC,GAClE,UAAU,CA6BZ;AA8PD,oBAAoB;AACpB,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEzD"}
package/dist/config.js DELETED
@@ -1,290 +0,0 @@
1
- import { merge } from 'merge-anything';
2
- import coreLintPlugin from './lint/plugin-core/index.js';
3
- import Logger from './logger.js';
4
- const TRAILING_SLASH_RE = /\/*$/;
5
- /**
6
- * Validate and normalize a config
7
- */
8
- export default function defineConfig(rawConfig, { logger = new Logger(), cwd } = {}) {
9
- const configStart = performance.now();
10
- if (!cwd) {
11
- logger.error({ group: 'config', label: 'core', message: 'defineConfig() missing `cwd` for JS API' });
12
- }
13
- const config = merge({}, rawConfig);
14
- // 1. normalize and init
15
- normalizeTokens({ rawConfig, config, logger, cwd });
16
- normalizeOutDir({ config, cwd, logger });
17
- normalizePlugins({ config, logger });
18
- normalizeLint({ config, logger });
19
- normalizeIgnore({ config, logger });
20
- // 2. Start build by calling config()
21
- for (const plugin of config.plugins) {
22
- plugin.config?.({ ...config });
23
- }
24
- // 3. finish
25
- logger.debug({
26
- group: 'parser',
27
- label: 'config',
28
- message: 'Finish config validation',
29
- timing: performance.now() - configStart,
30
- });
31
- return config;
32
- }
33
- /** Normalize config.tokens */
34
- function normalizeTokens({ rawConfig, config, logger, cwd, }) {
35
- if (rawConfig.tokens === undefined) {
36
- config.tokens = [
37
- // @ts-ignore we’ll normalize in next step
38
- './tokens.json',
39
- ];
40
- }
41
- else if (typeof rawConfig.tokens === 'string') {
42
- config.tokens = [
43
- // @ts-ignore we’ll normalize in next step
44
- rawConfig.tokens,
45
- ];
46
- }
47
- else if (Array.isArray(rawConfig.tokens)) {
48
- config.tokens = [];
49
- for (const file of rawConfig.tokens) {
50
- if (typeof file === 'string' || file instanceof URL) {
51
- config.tokens.push(
52
- // @ts-ignore we’ll normalize in next step
53
- file);
54
- }
55
- else {
56
- logger.error({
57
- group: 'config',
58
- label: 'tokens',
59
- message: `Expected array of strings, encountered ${JSON.stringify(file)}`,
60
- });
61
- }
62
- }
63
- }
64
- else {
65
- logger.error({
66
- group: 'config',
67
- label: 'tokens',
68
- message: `Expected string or array of strings, received ${typeof rawConfig.tokens}`,
69
- });
70
- }
71
- for (let i = 0; i < config.tokens.length; i++) {
72
- const filepath = config.tokens[i];
73
- if (filepath instanceof URL) {
74
- continue; // skip if already resolved
75
- }
76
- try {
77
- config.tokens[i] = new URL(filepath, cwd);
78
- }
79
- catch (err) {
80
- logger.error({ group: 'config', label: 'tokens', message: `Invalid URL ${filepath}` });
81
- }
82
- }
83
- }
84
- /** Normalize config.outDir */
85
- function normalizeOutDir({ config, cwd, logger }) {
86
- if (config.outDir instanceof URL) {
87
- // noop
88
- }
89
- else if (typeof config.outDir === 'undefined') {
90
- config.outDir = new URL('./tokens/', cwd);
91
- }
92
- else if (typeof config.outDir !== 'string') {
93
- logger.error({
94
- group: 'config',
95
- label: 'outDir',
96
- message: `Expected string, received ${JSON.stringify(config.outDir)}`,
97
- });
98
- }
99
- else {
100
- config.outDir = new URL(config.outDir, cwd);
101
- // always add trailing slash so URL treats it as a directory.
102
- // do AFTER it has been normalized to POSIX paths with `href` (don’t use Node internals here! This may run in the browser)
103
- config.outDir = new URL(config.outDir.href.replace(TRAILING_SLASH_RE, '/'));
104
- }
105
- }
106
- /** Normalize config.plugins */
107
- function normalizePlugins({ config, logger }) {
108
- if (typeof config.plugins === 'undefined') {
109
- config.plugins = [];
110
- }
111
- if (!Array.isArray(config.plugins)) {
112
- logger.error({
113
- group: 'config',
114
- label: 'plugins',
115
- message: `Expected array of plugins, received ${JSON.stringify(config.plugins)}`,
116
- });
117
- }
118
- config.plugins.push(coreLintPlugin());
119
- for (let n = 0; n < config.plugins.length; n++) {
120
- const plugin = config.plugins[n];
121
- if (typeof plugin !== 'object') {
122
- logger.error({
123
- group: 'config',
124
- label: `plugin[${n}]`,
125
- message: `Expected output plugin, received ${JSON.stringify(plugin)}`,
126
- });
127
- }
128
- else if (!plugin.name) {
129
- logger.error({ group: 'config', label: `plugin[${n}]`, message: `Missing "name"` });
130
- }
131
- }
132
- // order plugins with "enforce"
133
- config.plugins.sort((a, b) => {
134
- if (a.enforce === 'pre' && b.enforce !== 'pre') {
135
- return -1;
136
- }
137
- else if (a.enforce === 'post' && b.enforce !== 'post') {
138
- return 1;
139
- }
140
- return 0;
141
- });
142
- }
143
- function normalizeLint({ config, logger }) {
144
- if (config.lint !== undefined) {
145
- if (config.lint === null || typeof config.lint !== 'object' || Array.isArray(config.lint)) {
146
- logger.error({ group: 'config', label: 'lint', message: 'Must be an object' });
147
- }
148
- if (!config.lint.build) {
149
- config.lint.build = { enabled: true };
150
- }
151
- if (config.lint.build.enabled !== undefined) {
152
- if (typeof config.lint.build.enabled !== 'boolean') {
153
- logger.error({
154
- group: 'config',
155
- label: 'lint › build › enabled',
156
- message: `Expected boolean, received ${JSON.stringify(config.lint.build)}`,
157
- });
158
- }
159
- }
160
- else {
161
- config.lint.build.enabled = true;
162
- }
163
- if (config.lint.rules === undefined) {
164
- config.lint.rules = {};
165
- }
166
- else {
167
- if (config.lint.rules === null || typeof config.lint.rules !== 'object' || Array.isArray(config.lint.rules)) {
168
- logger.error({
169
- group: 'config',
170
- label: 'lint › rules',
171
- message: `Expected object, received ${JSON.stringify(config.lint.rules)}`,
172
- });
173
- return;
174
- }
175
- const allRules = new Map();
176
- for (const plugin of config.plugins) {
177
- if (typeof plugin.lint !== 'function') {
178
- continue;
179
- }
180
- const pluginRules = plugin.lint();
181
- if (!pluginRules || Array.isArray(pluginRules) || typeof pluginRules !== 'object') {
182
- logger.error({
183
- group: 'config',
184
- label: `plugin › ${plugin.name}`,
185
- message: `Expected object for lint() received ${JSON.stringify(pluginRules)}`,
186
- });
187
- continue;
188
- }
189
- for (const rule of Object.keys(pluginRules)) {
190
- // Note: sometimes plugins will be loaded multiple times, in which case it’s expected
191
- // they’re register rules again for lint(). Only throw an error if plugin A and plugin B’s
192
- // rules conflict.
193
- if (allRules.get(rule) && allRules.get(rule) !== plugin.name) {
194
- logger.error({
195
- group: 'config',
196
- label: `plugin › ${plugin.name}`,
197
- message: `Duplicate rule ${rule} already registered by plugin ${allRules.get(rule)}`,
198
- });
199
- }
200
- allRules.set(rule, plugin.name);
201
- }
202
- }
203
- for (const id of Object.keys(config.lint.rules)) {
204
- if (!allRules.has(id)) {
205
- logger.error({
206
- group: 'config',
207
- label: `lint › rule › ${id}`,
208
- message: 'Unknown rule. Is the plugin installed?',
209
- });
210
- }
211
- const value = config.lint.rules[id];
212
- let severity = 'off';
213
- let options;
214
- if (typeof value === 'number' || typeof value === 'string') {
215
- severity = value;
216
- }
217
- else if (Array.isArray(value)) {
218
- severity = value[0];
219
- options = value[1];
220
- }
221
- else if (value !== undefined) {
222
- logger.error({
223
- group: 'config',
224
- label: `lint › rule › ${id}`,
225
- message: `Invalid eyntax. Expected \`string | number | Array\`, received ${JSON.stringify(value)}}`,
226
- });
227
- }
228
- config.lint.rules[id] = [severity, options];
229
- if (typeof severity === 'number') {
230
- if (severity !== 0 && severity !== 1 && severity !== 2) {
231
- logger.error({
232
- group: 'config',
233
- label: `lint › rule › ${id}`,
234
- message: `Invalid number ${severity}. Specify 0 (off), 1 (warn), or 2 (error).`,
235
- });
236
- }
237
- config.lint.rules[id][0] = ['off', 'warn', 'error'][severity];
238
- }
239
- else if (typeof severity === 'string') {
240
- if (severity !== 'off' && severity !== 'warn' && severity !== 'error') {
241
- logger.error({
242
- group: 'config',
243
- label: `lint › rule › ${id}`,
244
- message: `Invalid string ${JSON.stringify(severity)}. Specify "off", "warn", or "error".`,
245
- });
246
- }
247
- }
248
- else if (value !== null) {
249
- logger.error({
250
- group: 'config',
251
- label: `lint › rule › ${id}`,
252
- message: `Expected string or number, received ${JSON.stringify(value)}`,
253
- });
254
- }
255
- }
256
- }
257
- }
258
- else {
259
- config.lint = {
260
- build: { enabled: true },
261
- rules: {},
262
- };
263
- }
264
- }
265
- function normalizeIgnore({ config, logger }) {
266
- if (!config.ignore) {
267
- config.ignore = {};
268
- }
269
- config.ignore.tokens ??= [];
270
- config.ignore.deprecated ??= false;
271
- if (!Array.isArray(config.ignore.tokens) || config.ignore.tokens.some((x) => typeof x !== 'string')) {
272
- logger.error({
273
- group: 'config',
274
- label: 'ignore › tokens',
275
- message: `Expected array of strings, received ${JSON.stringify(config.ignore.tokens)}`,
276
- });
277
- }
278
- if (typeof config.ignore.deprecated !== 'boolean') {
279
- logger.error({
280
- group: 'config',
281
- label: 'ignore › deprecated',
282
- message: `Expected boolean, received ${JSON.stringify(config.ignore.deprecated)}`,
283
- });
284
- }
285
- }
286
- /** Merge configs */
287
- export function mergeConfigs(a, b) {
288
- return merge(a, b);
289
- }
290
- //# sourceMappingURL=config.js.map