knip 6.30.0 → 6.32.0

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 (64) hide show
  1. package/dist/ConfigurationChief.d.ts +24 -0
  2. package/dist/DependencyDeputy.d.ts +2 -1
  3. package/dist/DependencyDeputy.js +2 -2
  4. package/dist/binaries/bash-parser.js +20 -8
  5. package/dist/binaries/fallback.js +6 -4
  6. package/dist/binaries/plugins.js +8 -4
  7. package/dist/binaries/resolvers/bun.js +7 -7
  8. package/dist/binaries/resolvers/bunx.d.ts +2 -1
  9. package/dist/binaries/resolvers/bunx.js +10 -6
  10. package/dist/binaries/resolvers/find.js +5 -5
  11. package/dist/binaries/resolvers/npm.js +5 -5
  12. package/dist/binaries/resolvers/npx.js +3 -4
  13. package/dist/binaries/resolvers/nub.js +4 -4
  14. package/dist/binaries/resolvers/pnpm.js +12 -9
  15. package/dist/binaries/resolvers/pnpx.d.ts +2 -1
  16. package/dist/binaries/resolvers/pnpx.js +4 -4
  17. package/dist/binaries/resolvers/yarn.js +17 -13
  18. package/dist/binaries/util.d.ts +6 -4
  19. package/dist/binaries/util.js +25 -3
  20. package/dist/compilers/index.d.ts +40 -0
  21. package/dist/graph/analyze.js +1 -0
  22. package/dist/graph/build.js +1 -0
  23. package/dist/plugins/babel/types.d.ts +1 -0
  24. package/dist/plugins/borp/index.d.ts +3 -0
  25. package/dist/plugins/borp/index.js +61 -0
  26. package/dist/plugins/borp/types.d.ts +4 -0
  27. package/dist/plugins/borp/types.js +1 -0
  28. package/dist/plugins/index.d.ts +4 -0
  29. package/dist/plugins/index.js +8 -0
  30. package/dist/plugins/jest/index.js +6 -2
  31. package/dist/plugins/marko/compiler.d.ts +2 -0
  32. package/dist/plugins/marko/compiler.js +85 -0
  33. package/dist/plugins/marko/index.d.ts +3 -0
  34. package/dist/plugins/marko/index.js +63 -0
  35. package/dist/plugins/marko/taglibs.d.ts +4 -0
  36. package/dist/plugins/marko/taglibs.js +111 -0
  37. package/dist/plugins/marko/types.d.ts +9 -0
  38. package/dist/plugins/marko/types.js +1 -0
  39. package/dist/plugins/mocha/index.js +59 -0
  40. package/dist/plugins/playwright/index.js +1 -1
  41. package/dist/plugins/pre-commit/index.d.ts +3 -0
  42. package/dist/plugins/pre-commit/index.js +23 -0
  43. package/dist/plugins/rollup/index.js +5 -1
  44. package/dist/plugins/tsd/index.d.ts +3 -0
  45. package/dist/plugins/tsd/index.js +43 -0
  46. package/dist/plugins/tsd/types.d.ts +4 -0
  47. package/dist/plugins/tsd/types.js +1 -0
  48. package/dist/schema/configuration.d.ts +60 -0
  49. package/dist/schema/plugins.d.ts +20 -0
  50. package/dist/schema/plugins.js +4 -0
  51. package/dist/types/PluginNames.d.ts +2 -2
  52. package/dist/types/PluginNames.js +4 -0
  53. package/dist/types/config.d.ts +4 -2
  54. package/dist/util/create-input-handler.js +2 -0
  55. package/dist/util/create-options.d.ts +40 -0
  56. package/dist/util/package-json.d.ts +4 -0
  57. package/dist/util/package-json.js +6 -2
  58. package/dist/util/parse-args.d.ts +2 -1
  59. package/dist/util/parse-args.js +8 -1
  60. package/dist/util/scripts.js +9 -5
  61. package/dist/version.d.ts +1 -1
  62. package/dist/version.js +1 -1
  63. package/package.json +3 -3
  64. package/schema.json +16 -0
@@ -43,6 +43,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
43
43
  entry?: string | string[] | undefined;
44
44
  project?: string | string[] | undefined;
45
45
  } | undefined;
46
+ borp?: string | boolean | string[] | {
47
+ config?: string | string[] | undefined;
48
+ entry?: string | string[] | undefined;
49
+ project?: string | string[] | undefined;
50
+ } | undefined;
46
51
  bumpp?: string | boolean | string[] | {
47
52
  config?: string | string[] | undefined;
48
53
  entry?: string | string[] | undefined;
@@ -298,6 +303,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
298
303
  entry?: string | string[] | undefined;
299
304
  project?: string | string[] | undefined;
300
305
  } | undefined;
306
+ marko?: string | boolean | string[] | {
307
+ config?: string | string[] | undefined;
308
+ entry?: string | string[] | undefined;
309
+ project?: string | string[] | undefined;
310
+ } | undefined;
301
311
  mdx?: string | boolean | string[] | {
302
312
  config?: string | string[] | undefined;
303
313
  entry?: string | string[] | undefined;
@@ -493,6 +503,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
493
503
  entry?: string | string[] | undefined;
494
504
  project?: string | string[] | undefined;
495
505
  } | undefined;
506
+ 'pre-commit'?: string | boolean | string[] | {
507
+ config?: string | string[] | undefined;
508
+ entry?: string | string[] | undefined;
509
+ project?: string | string[] | undefined;
510
+ } | undefined;
496
511
  preconstruct?: string | boolean | string[] | {
497
512
  config?: string | string[] | undefined;
498
513
  entry?: string | string[] | undefined;
@@ -723,6 +738,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
723
738
  entry?: string | string[] | undefined;
724
739
  project?: string | string[] | undefined;
725
740
  } | undefined;
741
+ tsd?: string | boolean | string[] | {
742
+ config?: string | string[] | undefined;
743
+ entry?: string | string[] | undefined;
744
+ project?: string | string[] | undefined;
745
+ } | undefined;
726
746
  tsdown?: string | boolean | string[] | {
727
747
  config?: string | string[] | undefined;
728
748
  entry?: string | string[] | undefined;
@@ -959,6 +979,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
959
979
  entry?: string | string[] | undefined;
960
980
  project?: string | string[] | undefined;
961
981
  } | undefined;
982
+ borp?: string | boolean | string[] | {
983
+ config?: string | string[] | undefined;
984
+ entry?: string | string[] | undefined;
985
+ project?: string | string[] | undefined;
986
+ } | undefined;
962
987
  bumpp?: string | boolean | string[] | {
963
988
  config?: string | string[] | undefined;
964
989
  entry?: string | string[] | undefined;
@@ -1214,6 +1239,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1214
1239
  entry?: string | string[] | undefined;
1215
1240
  project?: string | string[] | undefined;
1216
1241
  } | undefined;
1242
+ marko?: string | boolean | string[] | {
1243
+ config?: string | string[] | undefined;
1244
+ entry?: string | string[] | undefined;
1245
+ project?: string | string[] | undefined;
1246
+ } | undefined;
1217
1247
  mdx?: string | boolean | string[] | {
1218
1248
  config?: string | string[] | undefined;
1219
1249
  entry?: string | string[] | undefined;
@@ -1409,6 +1439,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1409
1439
  entry?: string | string[] | undefined;
1410
1440
  project?: string | string[] | undefined;
1411
1441
  } | undefined;
1442
+ 'pre-commit'?: string | boolean | string[] | {
1443
+ config?: string | string[] | undefined;
1444
+ entry?: string | string[] | undefined;
1445
+ project?: string | string[] | undefined;
1446
+ } | undefined;
1412
1447
  preconstruct?: string | boolean | string[] | {
1413
1448
  config?: string | string[] | undefined;
1414
1449
  entry?: string | string[] | undefined;
@@ -1639,6 +1674,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1639
1674
  entry?: string | string[] | undefined;
1640
1675
  project?: string | string[] | undefined;
1641
1676
  } | undefined;
1677
+ tsd?: string | boolean | string[] | {
1678
+ config?: string | string[] | undefined;
1679
+ entry?: string | string[] | undefined;
1680
+ project?: string | string[] | undefined;
1681
+ } | undefined;
1642
1682
  tsdown?: string | boolean | string[] | {
1643
1683
  config?: string | string[] | undefined;
1644
1684
  entry?: string | string[] | undefined;
@@ -196,6 +196,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
196
196
  const packageName = getPackageNameFromModuleSpecifier(extImport.specifier);
197
197
  const isHandled = packageName &&
198
198
  deputy.maybeAddReferencedExternalDependency(ws, packageName, {
199
+ specifier: extImport.specifier,
199
200
  isTypeOnly: extImport.isTypeOnly,
200
201
  isResolved: extImport.filePath !== undefined,
201
202
  });
@@ -117,6 +117,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
117
117
  if (getPublishedTypeDependencies && !manifest.private && !manifest.publishConfig?.directory) {
118
118
  for (const dependency of getPublishedTypeDependencies(workspace, manifest)) {
119
119
  const isHandled = deputy.maybeAddReferencedExternalDependency(workspace, dependency.packageName, {
120
+ specifier: dependency.specifier,
120
121
  isTypeOnly: true,
121
122
  isResolved: dependency.isResolved,
122
123
  isPublishedType: true,
@@ -1,6 +1,7 @@
1
1
  import type { api } from './helpers.ts';
2
2
  type BabelConfigFn = (options: typeof api) => BabelConfigObj;
3
3
  export type BabelConfigObj = {
4
+ configFile?: string;
4
5
  plugins?: (string | [string, unknown])[];
5
6
  presets?: (string | [string, unknown])[];
6
7
  env?: Record<string, BabelConfigObj>;
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.ts';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,61 @@
1
+ import { toDeferResolve, toEntry } from '../../util/input.js';
2
+ import { hasDependency } from '../../util/plugin.js';
3
+ const title = 'Borp';
4
+ const enablers = ['borp'];
5
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const config = ['.borp.yaml', '.borp.yml'];
7
+ const entry = ['**/*.test.{js,mjs,cjs,ts,mts,cts}'];
8
+ const builtinReporters = new Set(['spec', 'tap', 'dot', 'junit', 'lcov', 'gh']);
9
+ const toReporterInput = (reporter) => {
10
+ const separatorIndex = reporter.indexOf(':');
11
+ const name = separatorIndex === -1 ? reporter : reporter.slice(0, separatorIndex);
12
+ if (builtinReporters.has(name))
13
+ return;
14
+ return toDeferResolve(name);
15
+ };
16
+ const resolveConfig = async (localConfig) => {
17
+ const inputs = [];
18
+ for (const reporter of localConfig.reporters ?? []) {
19
+ const input = toReporterInput(reporter);
20
+ if (input)
21
+ inputs.push(input);
22
+ }
23
+ for (const id of localConfig.files ?? entry)
24
+ inputs.push(toEntry(id));
25
+ return inputs;
26
+ };
27
+ const args = {
28
+ boolean: ['coverage', 'watch', 'only', 'no-timeout', 'expose-gc', 'check-coverage', 'coverage-html'],
29
+ alias: {
30
+ coverage: ['C'],
31
+ watch: ['w'],
32
+ only: ['o'],
33
+ reporter: ['r'],
34
+ pattern: ['p'],
35
+ ignore: ['i'],
36
+ timeout: ['t'],
37
+ concurrency: ['c'],
38
+ 'coverage-exclude': ['X'],
39
+ },
40
+ resolveInputs: (parsed) => {
41
+ const inputs = [];
42
+ for (const reporter of [parsed.reporter ?? []].flat()) {
43
+ const input = toReporterInput(String(reporter));
44
+ if (input)
45
+ inputs.push(input);
46
+ }
47
+ for (const id of [...parsed._, parsed.pattern ?? []].flat())
48
+ inputs.push(toEntry(String(id)));
49
+ return inputs;
50
+ },
51
+ };
52
+ const plugin = {
53
+ title,
54
+ enablers,
55
+ isEnabled,
56
+ config,
57
+ entry,
58
+ resolveConfig,
59
+ args,
60
+ };
61
+ export default plugin;
@@ -0,0 +1,4 @@
1
+ export type BorpConfig = {
2
+ files?: string[];
3
+ reporters?: string[];
4
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -7,6 +7,7 @@ export declare const Plugins: {
7
7
  ava: import("../types/config.ts").Plugin;
8
8
  babel: import("../types/config.ts").Plugin;
9
9
  biome: import("../types/config.ts").Plugin;
10
+ borp: import("../types/config.ts").Plugin;
10
11
  bumpp: import("../types/config.ts").Plugin;
11
12
  bun: import("../types/config.ts").Plugin;
12
13
  c8: import("../types/config.ts").Plugin;
@@ -63,6 +64,7 @@ export declare const Plugins: {
63
64
  'lost-pixel': import("../types/config.ts").Plugin;
64
65
  lunaria: import("../types/config.ts").Plugin;
65
66
  markdownlint: import("../types/config.ts").Plugin;
67
+ marko: import("../types/config.ts").Plugin;
66
68
  mdx: import("../types/config.ts").Plugin;
67
69
  mdxlint: import("../types/config.ts").Plugin;
68
70
  metro: import("../types/config.ts").Plugin;
@@ -102,6 +104,7 @@ export declare const Plugins: {
102
104
  pm2: import("../types/config.ts").Plugin;
103
105
  pnpm: import("../types/config.ts").Plugin;
104
106
  postcss: import("../types/config.ts").Plugin;
107
+ 'pre-commit': import("../types/config.ts").Plugin;
105
108
  preconstruct: import("../types/config.ts").Plugin;
106
109
  prettier: import("../types/config.ts").Plugin;
107
110
  prisma: import("../types/config.ts").Plugin;
@@ -148,6 +151,7 @@ export declare const Plugins: {
148
151
  temporal: import("../types/config.ts").Plugin;
149
152
  travis: import("../types/config.ts").Plugin;
150
153
  'ts-node': import("../types/config.ts").Plugin;
154
+ tsd: import("../types/config.ts").Plugin;
151
155
  tsdown: import("../types/config.ts").Plugin;
152
156
  tsup: import("../types/config.ts").Plugin;
153
157
  tsx: import("../types/config.ts").Plugin;
@@ -6,6 +6,7 @@ import { default as astroOgCanvas } from './astro-og-canvas/index.js';
6
6
  import { default as ava } from './ava/index.js';
7
7
  import { default as babel } from './babel/index.js';
8
8
  import { default as biome } from './biome/index.js';
9
+ import { default as borp } from './borp/index.js';
9
10
  import { default as bumpp } from './bumpp/index.js';
10
11
  import { default as bun } from './bun/index.js';
11
12
  import { default as c8 } from './c8/index.js';
@@ -57,6 +58,7 @@ import { default as lockfileLint } from './lockfile-lint/index.js';
57
58
  import { default as lostPixel } from './lost-pixel/index.js';
58
59
  import { default as lunaria } from './lunaria/index.js';
59
60
  import { default as markdownlint } from './markdownlint/index.js';
61
+ import { default as marko } from './marko/index.js';
60
62
  import { default as mdx } from './mdx/index.js';
61
63
  import { default as mdxlint } from './mdxlint/index.js';
62
64
  import { default as metro } from './metro/index.js';
@@ -96,6 +98,7 @@ import { default as plop } from './plop/index.js';
96
98
  import { default as pm2 } from './pm2/index.js';
97
99
  import { default as pnpm } from './pnpm/index.js';
98
100
  import { default as postcss } from './postcss/index.js';
101
+ import { default as preCommit } from './pre-commit/index.js';
99
102
  import { default as preconstruct } from './preconstruct/index.js';
100
103
  import { default as prettier } from './prettier/index.js';
101
104
  import { default as prisma } from './prisma/index.js';
@@ -142,6 +145,7 @@ import { default as tauri } from './tauri/index.js';
142
145
  import { default as temporal } from './temporal/index.js';
143
146
  import { default as travis } from './travis/index.js';
144
147
  import { default as tsNode } from './ts-node/index.js';
148
+ import { default as tsd } from './tsd/index.js';
145
149
  import { default as tsdown } from './tsdown/index.js';
146
150
  import { default as tsup } from './tsup/index.js';
147
151
  import { default as tsx } from './tsx/index.js';
@@ -185,6 +189,7 @@ export const Plugins = {
185
189
  ava,
186
190
  babel,
187
191
  biome,
192
+ borp,
188
193
  bumpp,
189
194
  bun,
190
195
  c8,
@@ -236,6 +241,7 @@ export const Plugins = {
236
241
  'lost-pixel': lostPixel,
237
242
  lunaria,
238
243
  markdownlint,
244
+ marko,
239
245
  mdx,
240
246
  mdxlint,
241
247
  metro,
@@ -275,6 +281,7 @@ export const Plugins = {
275
281
  pm2,
276
282
  pnpm,
277
283
  postcss,
284
+ 'pre-commit': preCommit,
278
285
  preconstruct,
279
286
  prettier,
280
287
  prisma,
@@ -321,6 +328,7 @@ export const Plugins = {
321
328
  temporal,
322
329
  travis,
323
330
  'ts-node': tsNode,
331
+ tsd,
324
332
  tsdown,
325
333
  tsup,
326
334
  tsx,
@@ -1,6 +1,6 @@
1
1
  import { arrayify } from '../../util/array.js';
2
2
  import { _glob, _dirGlob } from '../../util/glob.js';
3
- import { toDeferResolve, toEntry } from '../../util/input.js';
3
+ import { toConfig, toDeferResolve, toEntry } from '../../util/input.js';
4
4
  import { isInternal, join, normalize, toAbsolute } from '../../util/path.js';
5
5
  import { hasDependency } from '../../util/plugin.js';
6
6
  import { getDependenciesFromConfig } from '../babel/index.js';
@@ -55,8 +55,12 @@ const resolveDependencies = async (config, rootDir, options) => {
55
55
  }
56
56
  else {
57
57
  transform.push(transformer[0]);
58
- if (isBabelJest(transformer))
58
+ if (isBabelJest(transformer)) {
59
59
  transform.push(...getDependenciesFromConfig(transformer[1]));
60
+ const { configFile } = transformer[1];
61
+ if (typeof configFile === 'string')
62
+ transform.push(toConfig('babel', rootDirRe.test(configFile) ? configFile : toAbsolute(configFile, options.cwd)));
63
+ }
60
64
  }
61
65
  }
62
66
  const moduleNameMapper = (config.moduleNameMapper
@@ -0,0 +1,2 @@
1
+ import type { CompilerSync } from '../../compilers/types.ts';
2
+ export declare const createCompiler: (tagDependencies?: Map<string, string[]>, fallbackDependencies?: string[]) => CompilerSync;
@@ -0,0 +1,85 @@
1
+ import { getStyleLang, styleExtractor } from '../../compilers/compilers.js';
2
+ import { compiler as lessCompiler } from '../../compilers/less.js';
3
+ import { compiler as scssCompiler } from '../../compilers/scss.js';
4
+ import { compiler as stylusCompiler } from '../../compilers/stylus.js';
5
+ const commentMatcher = /<!--[\s\S]*?-->|\/\*[\s\S]*?\*\/|^[ \t]*\/\/.*$/gm;
6
+ const conciseStyleMatcher = /^[ \t]*style(?:\.([\w.-]+))?[^\n{]*\{([\s\S]*?)^[ \t]*\}/gm;
7
+ const htmlTagMatcher = /<([a-z][\w.-]*)(?=[\s/|>])/g;
8
+ const conciseTagMatcher = /^[ \t]*([a-z][\w.-]*)(?=[ \t/|]|--|$)/gm;
9
+ const tagImportMatcher = /^[ \t]*(?:(?:server|client|static|\$)[ \t]+)?import[ \t\r\n]+(?:type[ \t\r\n]+)?(?:[$\w]+(?:[ \t\r\n]*,[ \t\r\n]*(?:\*[ \t\r\n]+as[ \t\r\n]+[$\w]+|\{[^}]*\}))?|\*[ \t\r\n]+as[ \t\r\n]+[$\w]+|\{[^}]*\})[ \t\r\n]+from[ \t\r\n]*(["'])<[^"'\r\n]+>\1(?:[ \t\r\n]+with[ \t\r\n]*\{(?:[^}"']+|"[^"]*"|'[^']*')*\})?[ \t]*;?[ \t]*(?:\r?\n|$)/gm;
10
+ const markupLineMatcher = /^[ \t]*<.*$/gm;
11
+ const markoPrefixMatcher = /^([ \t]*)(?:server|client|\$)[ \t]+/gm;
12
+ const staticPrefixMatcher = /^([ \t]*)static[ \t]+(?=(?:import|export|const|let|var|function|class|interface|type|enum|namespace|async[ \t]+function)\b)/gm;
13
+ const staticBlockPrefixMatcher = /^([ \t]*)static[ \t]+(?=\{)/gm;
14
+ const classBodyMatcher = /^([ \t]*)class\b[^{]*\{[\s\S]*?^\1\}/gm;
15
+ const classStaticBlockMatcher = /^([ \t]*)static(?=[ \t]*\{)/gm;
16
+ const classStaticBlockPlaceholder = '__MARKO_CLASS_STATIC_BLOCK__';
17
+ const anonymousClassMatcher = /^([ \t]*)class[ \t]*\{/gm;
18
+ const localExportDeclarationMatcher = /^([ \t]*)export[ \t]+(?:default[ \t]+)?(?=(?:(?:declare|abstract|async)[ \t]+)*(?:interface|type[ \t]+[$\w]+|const|let|var|function|class|enum|namespace)\b)/gm;
19
+ const localExportListMatcher = /^[ \t]*export[ \t]+(?:type[ \t]+)?\{[^}]*\}(?![ \t\r\n]*from\b)[ \t]*;?[ \t]*(?=\r?$)/gm;
20
+ const compileStyle = (body, lang, path) => {
21
+ switch (lang) {
22
+ case 'less':
23
+ return lessCompiler(body, path);
24
+ case 'styl':
25
+ case 'stylus':
26
+ return stylusCompiler(body, path);
27
+ default:
28
+ return scssCompiler(body, path);
29
+ }
30
+ };
31
+ const collectStyles = (text, path) => {
32
+ const imports = [];
33
+ styleExtractor.lastIndex = 0;
34
+ let match;
35
+ while ((match = styleExtractor.exec(text))) {
36
+ const lang = getStyleLang(match[1]) ?? match[1].match(/\.([\w-]+)/)?.[1];
37
+ const output = compileStyle(match[2], lang, path);
38
+ if (output)
39
+ imports.push(output);
40
+ }
41
+ conciseStyleMatcher.lastIndex = 0;
42
+ while ((match = conciseStyleMatcher.exec(text))) {
43
+ const output = compileStyle(match[2], match[1]?.split('.').pop(), path);
44
+ if (output)
45
+ imports.push(output);
46
+ }
47
+ return imports;
48
+ };
49
+ const sanitize = (text) => {
50
+ const source = text
51
+ .replace(styleExtractor, '')
52
+ .replace(conciseStyleMatcher, '')
53
+ .replace(tagImportMatcher, '')
54
+ .replace(markupLineMatcher, '')
55
+ .replace(markoPrefixMatcher, '$1')
56
+ .replace(staticPrefixMatcher, '$1')
57
+ .replace(localExportDeclarationMatcher, '$1')
58
+ .replace(localExportListMatcher, '');
59
+ return source
60
+ .replace(classBodyMatcher, body => body.replace(classStaticBlockMatcher, `$1${classStaticBlockPlaceholder}`))
61
+ .replace(staticBlockPrefixMatcher, '$1')
62
+ .replaceAll(classStaticBlockPlaceholder, 'static')
63
+ .replace(anonymousClassMatcher, '$1class MarkoComponent {');
64
+ };
65
+ const collectTagDependencies = (text, tagDependencies, fallbackDependencies) => {
66
+ const dependencies = new Set(fallbackDependencies);
67
+ for (const matcher of [htmlTagMatcher, conciseTagMatcher]) {
68
+ matcher.lastIndex = 0;
69
+ let match;
70
+ while ((match = matcher.exec(text))) {
71
+ for (const dependency of tagDependencies.get(match[1]) ?? [])
72
+ dependencies.add(dependency);
73
+ }
74
+ }
75
+ return Array.from(dependencies, dependency => `import "${dependency}";`);
76
+ };
77
+ export const createCompiler = (tagDependencies = new Map(), fallbackDependencies = []) => (text, path) => {
78
+ const source = text.replace(commentMatcher, '');
79
+ return [
80
+ 'import "marko";',
81
+ ...collectTagDependencies(source, tagDependencies, fallbackDependencies),
82
+ ...collectStyles(source, path),
83
+ sanitize(source),
84
+ ].join('\n');
85
+ };
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.ts';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,63 @@
1
+ import { toDeferResolve, toProductionEntry } from '../../util/input.js';
2
+ import { join, relative } from '../../util/path.js';
3
+ import { hasDependency } from '../../util/plugin.js';
4
+ import { createCompiler } from './compiler.js';
5
+ import { getTaglibDependencies } from './taglibs.js';
6
+ const title = 'Marko';
7
+ const enablers = ['marko'];
8
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
9
+ const config = ['**/marko.json', '**/marko-tag.json'];
10
+ const tagDiscoveryDirs = ['components', 'tags'];
11
+ const scriptExtensions = '{js,jsx,ts,tsx,mjs,cjs,mts,cts}';
12
+ const styleExtensions = '{css,less,scss,sass,styl,stylus}';
13
+ const tagFilePatterns = [
14
+ '**/*.marko',
15
+ `**/{component,component-browser}.${scriptExtensions}`,
16
+ `**/*.{component,component-browser}.${scriptExtensions}`,
17
+ `**/style.${styleExtensions}`,
18
+ `**/*.style.${styleExtensions}`,
19
+ ];
20
+ const tagProduction = tagFilePatterns.map(pattern => `**/{${tagDiscoveryDirs.join(',')}}/${pattern}`);
21
+ const production = tagProduction;
22
+ const tagDefFields = [
23
+ 'template',
24
+ 'renderer',
25
+ 'parse',
26
+ 'migrate',
27
+ 'transform',
28
+ 'analyze',
29
+ 'translate',
30
+ ];
31
+ const resolveConfig = (localConfig, options) => {
32
+ const { configFileName, configFileDir, cwd } = options;
33
+ const inputs = [];
34
+ if (!localConfig)
35
+ return inputs;
36
+ if (configFileName === 'marko.json') {
37
+ const dir = relative(cwd, configFileDir);
38
+ return tagProduction.map(pattern => toProductionEntry(join(dir, pattern)));
39
+ }
40
+ for (const field of tagDefFields) {
41
+ for (const id of [localConfig[field]].flat()) {
42
+ if (typeof id === 'string')
43
+ inputs.push(toDeferResolve(join(configFileDir, id)));
44
+ }
45
+ }
46
+ return inputs;
47
+ };
48
+ const registerCompilers = async ({ cwd, registerCompiler, hasDependency }) => {
49
+ if (hasDependency('marko')) {
50
+ const { tagDependencies, fallbackDependencies } = await getTaglibDependencies(cwd);
51
+ registerCompiler({ extension: '.marko', compiler: createCompiler(tagDependencies, fallbackDependencies) });
52
+ }
53
+ };
54
+ const plugin = {
55
+ title,
56
+ enablers,
57
+ isEnabled,
58
+ config,
59
+ production,
60
+ resolveConfig,
61
+ registerCompilers,
62
+ };
63
+ export default plugin;
@@ -0,0 +1,4 @@
1
+ export declare const getTaglibDependencies: (cwd: string) => Promise<{
2
+ tagDependencies: Map<string, string[]>;
3
+ fallbackDependencies: string[];
4
+ }>;
@@ -0,0 +1,111 @@
1
+ import { readdirSync } from 'node:fs';
2
+ import { isFile, loadJSON } from '../../util/fs.js';
3
+ import { basename, dirname, join } from '../../util/path.js';
4
+ const dependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
5
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
6
+ const getDependencies = async (cwd) => {
7
+ const manifest = await loadJSON(join(cwd, 'package.json'));
8
+ const dependencies = new Set();
9
+ if (!isRecord(manifest))
10
+ return dependencies;
11
+ for (const field of dependencyFields) {
12
+ const values = manifest[field];
13
+ if (isRecord(values))
14
+ for (const packageName in values)
15
+ dependencies.add(packageName);
16
+ }
17
+ return dependencies;
18
+ };
19
+ const findConfig = (cwd, packageName) => {
20
+ let dir = cwd;
21
+ while (true) {
22
+ const filePath = join(dir, 'node_modules', packageName, 'marko.json');
23
+ if (isFile(filePath))
24
+ return filePath;
25
+ const parent = dirname(dir);
26
+ if (parent === dir)
27
+ return;
28
+ dir = parent;
29
+ }
30
+ };
31
+ const readDir = (dir) => {
32
+ try {
33
+ return readdirSync(dir, { withFileTypes: true });
34
+ }
35
+ catch {
36
+ return [];
37
+ }
38
+ };
39
+ const getTagName = (fileName) => (fileName.endsWith('.marko') ? basename(fileName, '.marko') : undefined);
40
+ const isTagDir = (dir, name) => isFile(dir, 'index.marko') || isFile(dir, `${name}.marko`);
41
+ const getTags = (dir) => {
42
+ const tags = new Set();
43
+ for (const entry of readDir(dir)) {
44
+ if (entry.name.startsWith('.'))
45
+ continue;
46
+ if (entry.isFile()) {
47
+ const name = getTagName(entry.name);
48
+ if (name)
49
+ tags.add(name);
50
+ continue;
51
+ }
52
+ if (!entry.isDirectory())
53
+ continue;
54
+ const tagDir = join(dir, entry.name);
55
+ if (isTagDir(tagDir, entry.name)) {
56
+ tags.add(entry.name);
57
+ continue;
58
+ }
59
+ if (entry.name === 'tags' || entry.name === 'components')
60
+ continue;
61
+ for (const child of readDir(tagDir)) {
62
+ if (child.isFile()) {
63
+ const name = getTagName(child.name);
64
+ if (name)
65
+ tags.add(name);
66
+ }
67
+ else if (child.isDirectory() && isTagDir(join(tagDir, child.name), child.name)) {
68
+ tags.add(child.name);
69
+ }
70
+ }
71
+ }
72
+ return tags;
73
+ };
74
+ export const getTaglibDependencies = async (cwd) => {
75
+ const tagDependencies = new Map();
76
+ const fallbackDependencies = [];
77
+ for (const packageName of await getDependencies(cwd)) {
78
+ const configPath = findConfig(cwd, packageName);
79
+ if (!configPath)
80
+ continue;
81
+ let config;
82
+ try {
83
+ config = await loadJSON(configPath);
84
+ }
85
+ catch {
86
+ fallbackDependencies.push(packageName);
87
+ continue;
88
+ }
89
+ if (!isRecord(config)) {
90
+ fallbackDependencies.push(packageName);
91
+ continue;
92
+ }
93
+ const tagsDir = typeof config.exports === 'string'
94
+ ? config.exports
95
+ : typeof config['tags-dir'] === 'string'
96
+ ? config['tags-dir']
97
+ : undefined;
98
+ if (!tagsDir) {
99
+ fallbackDependencies.push(packageName);
100
+ continue;
101
+ }
102
+ for (const tagName of getTags(join(dirname(configPath), tagsDir))) {
103
+ const dependencies = tagDependencies.get(tagName);
104
+ if (dependencies)
105
+ dependencies.push(packageName);
106
+ else
107
+ tagDependencies.set(tagName, [packageName]);
108
+ }
109
+ }
110
+ return { tagDependencies, fallbackDependencies };
111
+ };
@@ -0,0 +1,9 @@
1
+ export type MarkoTagDef = {
2
+ template?: string;
3
+ renderer?: string;
4
+ parse?: string;
5
+ migrate?: string;
6
+ transform?: string;
7
+ analyze?: string;
8
+ translate?: string;
9
+ };
@@ -0,0 +1 @@
1
+ export {};