@xylabs/ts-scripts-yarn3 6.5.18 → 7.0.0-rc.10

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 (38) hide show
  1. package/dist/actions/index.mjs +110 -130
  2. package/dist/actions/index.mjs.map +1 -1
  3. package/dist/actions/package/compile/buildEntries.mjs +8 -1
  4. package/dist/actions/package/compile/buildEntries.mjs.map +1 -1
  5. package/dist/actions/package/compile/compile.mjs +87 -107
  6. package/dist/actions/package/compile/compile.mjs.map +1 -1
  7. package/dist/actions/package/compile/index.mjs +88 -108
  8. package/dist/actions/package/compile/index.mjs.map +1 -1
  9. package/dist/actions/package/compile/packageCompileTsc.mjs +9 -35
  10. package/dist/actions/package/compile/packageCompileTsc.mjs.map +1 -1
  11. package/dist/actions/package/compile/packageCompileTscTypes.mjs +29 -102
  12. package/dist/actions/package/compile/packageCompileTscTypes.mjs.map +1 -1
  13. package/dist/actions/package/compile/packageCompileTsup.mjs +96 -135
  14. package/dist/actions/package/compile/packageCompileTsup.mjs.map +1 -1
  15. package/dist/actions/package/index.mjs +100 -120
  16. package/dist/actions/package/index.mjs.map +1 -1
  17. package/dist/actions/package/recompile.mjs +87 -107
  18. package/dist/actions/package/recompile.mjs.map +1 -1
  19. package/dist/bin/package/build-only.mjs +89 -109
  20. package/dist/bin/package/build-only.mjs.map +1 -1
  21. package/dist/bin/package/build.mjs +89 -109
  22. package/dist/bin/package/build.mjs.map +1 -1
  23. package/dist/bin/package/compile-only.mjs +89 -109
  24. package/dist/bin/package/compile-only.mjs.map +1 -1
  25. package/dist/bin/package/compile-tsup.mjs +101 -140
  26. package/dist/bin/package/compile-tsup.mjs.map +1 -1
  27. package/dist/bin/package/compile.mjs +89 -109
  28. package/dist/bin/package/compile.mjs.map +1 -1
  29. package/dist/bin/package/recompile.mjs +89 -109
  30. package/dist/bin/package/recompile.mjs.map +1 -1
  31. package/dist/index.d.ts +24 -7
  32. package/dist/index.mjs +122 -142
  33. package/dist/index.mjs.map +1 -1
  34. package/package.json +8 -5
  35. package/dist/actions/package/compile/compileTypes.mjs +0 -138
  36. package/dist/actions/package/compile/compileTypes.mjs.map +0 -1
  37. package/dist/bin/package/compile-types.mjs +0 -150
  38. package/dist/bin/package/compile-types.mjs.map +0 -1
@@ -1,113 +1,40 @@
1
1
  // src/actions/package/compile/packageCompileTscTypes.ts
2
2
  import { cwd } from "process";
3
- import chalk from "chalk";
4
- import { createProgramFromConfig } from "tsc-prog";
5
- import {
6
- DiagnosticCategory,
7
- formatDiagnosticsWithColorAndContext,
8
- getPreEmitDiagnostics,
9
- sys as sys2
10
- } from "typescript";
11
-
12
- // src/actions/package/compile/inputs.ts
13
- import { glob } from "glob";
14
- var getAllInputs = (folder) => {
15
- return glob.sync(`${folder}/**/*.*`, { posix: true });
16
- };
17
-
18
- // src/actions/package/compile/buildEntries.ts
19
- var buildEntries = (folder, entryMode = "single", excludeSpecAndStories = true, verbose = false) => {
20
- let entries = [];
21
- switch (entryMode) {
22
- case "platform": {
23
- entries = [`${folder}/index-node.ts`, `${folder}/index-browser.ts`];
24
- break;
25
- }
26
- case "all": {
27
- entries = excludeSpecAndStories ? getAllInputs(folder).filter((entry) => !entry.includes(".spec.") && !entry.includes(".stories.")) : getAllInputs(folder);
28
- break;
29
- }
30
- default: {
31
- entries = [`${folder}/index.ts`];
32
- break;
3
+ import { rollup } from "rollup";
4
+ import dts from "rollup-plugin-dts";
5
+ import nodeExternals from "rollup-plugin-node-externals";
6
+ async function bundleDts(inputPath, outputPath, platform) {
7
+ const nodePlugIns = platform === "node" ? [nodeExternals()] : [];
8
+ const bundle = await rollup({
9
+ input: inputPath,
10
+ plugins: [dts(), ...nodePlugIns],
11
+ onwarn(warning, warn) {
12
+ if (warning.code === "UNUSED_EXTERNAL_IMPORT") return;
13
+ warn(warning);
33
14
  }
34
- }
35
- if (verbose) console.log(`buildEntries [${entryMode}] ${entries.length}`);
36
- return entries;
37
- };
38
-
39
- // src/actions/package/compile/getCompilerOptions.ts
40
- import { createRequire } from "module";
41
- import deepmerge from "deepmerge";
42
- import {
43
- findConfigFile,
44
- readConfigFile,
45
- sys
46
- } from "typescript";
47
- var getNested = (config) => {
48
- if (config.extends) {
49
- const require2 = createRequire(import.meta.url);
50
- const opts = require2(config.extends);
51
- return deepmerge(getNested(opts), config.compilerOptions ?? {});
52
- }
53
- return config.compilerOptions;
54
- };
55
- var getCompilerOptionsJSONFollowExtends = (filename) => {
56
- const config = readConfigFile(filename, sys.readFile).config;
57
- return getNested(config);
58
- };
59
- var getCompilerOptions = (options = {}, tsconfig = "tsconfig.json") => {
60
- const configFileName = findConfigFile("./", sys.fileExists, tsconfig);
61
- const configFileCompilerOptions = (configFileName ? getCompilerOptionsJSONFollowExtends(configFileName) : void 0) ?? {};
62
- return deepmerge(configFileCompilerOptions, options);
63
- };
64
-
65
- // src/actions/package/compile/packageCompileTscTypes.ts
66
- var packageCompileTscTypes = (folder = "src", config = {}, compilerOptionsParam) => {
15
+ });
16
+ await bundle.write({
17
+ file: outputPath,
18
+ format: "es"
19
+ });
20
+ console.log(`Bundled declarations written to ${outputPath}`);
21
+ }
22
+ var packageCompileTscTypes = async (entries, outDir, platform, folder = "src") => {
67
23
  const pkg = process.env.INIT_CWD ?? cwd();
68
- const verbose = config?.verbose ?? false;
69
- const compilerOptions = {
70
- ...getCompilerOptions({
71
- emitDeclarationOnly: true,
72
- outDir: config.compile?.tsup?.options?.outDir ?? "dist/types",
73
- removeComments: false,
74
- skipDefaultLibCheck: true,
75
- skipLibCheck: true,
76
- sourceMap: false
77
- }),
78
- ...compilerOptionsParam,
79
- emitDeclarationOnly: true,
80
- noEmit: false
24
+ const srcRoot = `${pkg}/${folder}`;
25
+ const entryNameToTypeName = (entry) => {
26
+ const splitEntryName = entry.split(".");
27
+ const newEntryExtension = "d." + splitEntryName.at(-1);
28
+ return [...splitEntryName.slice(0, -1), newEntryExtension].join(".");
81
29
  };
82
- const validTsExt = [".ts", ".tsx", ".d.ts", ".cts", ".d.cts", ".mts", ".d.mts"];
83
- const excludes = [".stories.", ".spec.", "/stories/", "/spec/"];
84
- const files = buildEntries(folder, "all", verbose).filter((file) => validTsExt.find((ext) => file.endsWith(ext)) && !excludes.some((exclude) => file.includes(exclude)));
85
- console.log(chalk.green(`Compiling Types ${pkg}: ${files.length}`));
86
- if (files.length > 0) {
87
- const program = createProgramFromConfig({
88
- basePath: pkg ?? cwd(),
89
- compilerOptions,
90
- exclude: ["build", "dist", "docs", "**/*.spec.*", "**/*.stories.*", "src/**/spec/**/*"],
91
- files
92
- });
93
- const diagnostics = getPreEmitDiagnostics(program);
94
- if (diagnostics.length > 0) {
95
- const formattedDiagnostics = formatDiagnosticsWithColorAndContext(
96
- diagnostics,
97
- {
98
- getCanonicalFileName: (fileName) => fileName,
99
- getCurrentDirectory: () => folder,
100
- getNewLine: () => sys2.newLine
101
- }
102
- );
103
- console.error(formattedDiagnostics);
104
- }
105
- program.emit();
106
- return diagnostics.reduce((acc, diag) => acc + (diag.category === DiagnosticCategory.Error ? 1 : 0), 0);
107
- }
30
+ const entryNames = entries.map((entry) => entry.split(`${folder}/`).at(-1) ?? entry);
31
+ await Promise.all(entryNames.map(async (entryName) => {
32
+ await bundleDts(`${srcRoot}/${entryName}`, outDir + "/" + entryNameToTypeName(entryName), platform);
33
+ }));
108
34
  return 0;
109
35
  };
110
36
  export {
37
+ bundleDts,
111
38
  packageCompileTscTypes
112
39
  };
113
40
  //# sourceMappingURL=packageCompileTscTypes.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/actions/package/compile/packageCompileTscTypes.ts","../../../../src/actions/package/compile/inputs.ts","../../../../src/actions/package/compile/buildEntries.ts","../../../../src/actions/package/compile/getCompilerOptions.ts"],"sourcesContent":["import { cwd } from 'node:process'\n\nimport chalk from 'chalk'\nimport type { TsConfigCompilerOptions } from 'tsc-prog'\nimport { createProgramFromConfig } from 'tsc-prog'\nimport type { CompilerOptions } from 'typescript'\nimport {\n DiagnosticCategory, formatDiagnosticsWithColorAndContext, getPreEmitDiagnostics, sys,\n} from 'typescript'\n\nimport { buildEntries } from './buildEntries.ts'\nimport { getCompilerOptions } from './getCompilerOptions.ts'\nimport type { XyConfig, XyTsupConfig } from './XyConfig.ts'\n\nexport const packageCompileTscTypes = (\n folder: string = 'src',\n config: XyConfig = {},\n compilerOptionsParam?: CompilerOptions,\n): number => {\n const pkg = process.env.INIT_CWD ?? cwd()\n const verbose = config?.verbose ?? false\n\n const compilerOptions = {\n ...(getCompilerOptions({\n emitDeclarationOnly: true,\n outDir: (config as XyTsupConfig).compile?.tsup?.options?.outDir ?? 'dist/types',\n removeComments: false,\n skipDefaultLibCheck: true,\n skipLibCheck: true,\n sourceMap: false,\n })),\n ...compilerOptionsParam,\n emitDeclarationOnly: true,\n noEmit: false,\n } as TsConfigCompilerOptions\n\n const validTsExt = ['.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts']\n const excludes = ['.stories.', '.spec.', '/stories/', '/spec/']\n\n // calling all here since the types do not get rolled up\n const files = buildEntries(folder, 'all', verbose)\n .filter(file => validTsExt.find(ext => file.endsWith(ext)) && !(excludes.some(exclude => file.includes(exclude))))\n\n console.log(chalk.green(`Compiling Types ${pkg}: ${files.length}`))\n\n if (files.length > 0) {\n const program = createProgramFromConfig({\n basePath: pkg ?? cwd(),\n compilerOptions,\n exclude: ['build', 'dist', 'docs', '**/*.spec.*', '**/*.stories.*', 'src/**/spec/**/*'],\n files,\n })\n\n const diagnostics = getPreEmitDiagnostics(program)\n\n if (diagnostics.length > 0) {\n const formattedDiagnostics = formatDiagnosticsWithColorAndContext(\n diagnostics,\n {\n getCanonicalFileName: fileName => fileName,\n getCurrentDirectory: () => folder,\n getNewLine: () => sys.newLine,\n },\n )\n console.error(formattedDiagnostics)\n }\n\n program.emit()\n return diagnostics.reduce((acc, diag) => acc + (diag.category === DiagnosticCategory.Error ? 1 : 0), 0)\n }\n return 0\n}\n","import { glob } from 'glob'\n\nexport const getAllInputs = (folder: string) => {\n /* tsup wants posix paths */\n return glob.sync(`${folder}/**/*.*`, { posix: true })\n}\n","import { getAllInputs } from './inputs.ts'\nimport type { EntryMode } from './XyConfig.ts'\n\nexport const buildEntries = (folder: string, entryMode: EntryMode = 'single', excludeSpecAndStories = true, verbose = false) => {\n let entries: string[] = []\n switch (entryMode) {\n case 'platform': {\n entries = [`${folder}/index-node.ts`, `${folder}/index-browser.ts`]\n break\n }\n case 'all': {\n entries = excludeSpecAndStories ? getAllInputs(folder).filter(entry => !entry.includes('.spec.') && !entry.includes('.stories.')) : getAllInputs(folder)\n break\n }\n default: {\n entries = [`${folder}/index.ts`]\n break\n }\n }\n if (verbose) console.log(`buildEntries [${entryMode}] ${entries.length}`)\n return entries\n}\n","import { createRequire } from 'node:module'\n\nimport deepmerge from 'deepmerge'\nimport type { TsConfig } from 'tsc-prog'\nimport type { CompilerOptions } from 'typescript'\nimport {\n findConfigFile, readConfigFile, sys,\n} from 'typescript'\n\nconst getNested = (config: TsConfig): CompilerOptions => {\n if (config.extends) {\n const require = createRequire(import.meta.url)\n const opts = require(config.extends)\n return deepmerge(getNested(opts), config.compilerOptions ?? {}) as CompilerOptions\n }\n\n return config.compilerOptions as CompilerOptions\n}\n\nconst getCompilerOptionsJSONFollowExtends = (filename: string): CompilerOptions => {\n const config = readConfigFile(filename, sys.readFile).config\n return getNested(config)\n}\n\nexport const getCompilerOptions = (options: CompilerOptions = {}, tsconfig: string = 'tsconfig.json'): CompilerOptions => {\n const configFileName = findConfigFile('./', sys.fileExists, tsconfig)\n const configFileCompilerOptions = (configFileName ? getCompilerOptionsJSONFollowExtends(configFileName) : undefined) ?? {}\n\n return deepmerge(configFileCompilerOptions, options)\n}\n"],"mappings":";AAAA,SAAS,WAAW;AAEpB,OAAO,WAAW;AAElB,SAAS,+BAA+B;AAExC;AAAA,EACE;AAAA,EAAoB;AAAA,EAAsC;AAAA,EAAuB,OAAAA;AAAA,OAC5E;;;ACRP,SAAS,YAAY;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A,UAC3B,YAAY,MAAMC,KAAI;AAAA,QACxB;AAAA,MACF;AACA,cAAQ,MAAM,oBAAoB;AAAA,IACpC;AAEA,YAAQ,KAAK;AACb,WAAO,YAAY,OAAO,CAAC,KAAK,SAAS,OAAO,KAAK,aAAa,mBAAmB,QAAQ,IAAI,IAAI,CAAC;AAAA,EACxG;AACA,SAAO;AACT;","names":["sys","require","sys"]}
1
+ {"version":3,"sources":["../../../../src/actions/package/compile/packageCompileTscTypes.ts"],"sourcesContent":["import { cwd } from 'node:process'\n\nimport { rollup } from 'rollup'\nimport dts from 'rollup-plugin-dts'\nimport nodeExternals from 'rollup-plugin-node-externals'\n\nexport async function bundleDts(inputPath: string, outputPath: string, platform: 'node' | 'browser' | 'neutral') {\n const nodePlugIns = platform === 'node' ? [nodeExternals()] : []\n const bundle = await rollup({\n input: inputPath,\n plugins: [dts(), ...nodePlugIns],\n onwarn(warning, warn) {\n // Ignore certain warnings if needed\n if (warning.code === 'UNUSED_EXTERNAL_IMPORT') return\n warn(warning)\n },\n })\n\n await bundle.write({\n file: outputPath,\n format: 'es',\n })\n\n console.log(`Bundled declarations written to ${outputPath}`)\n}\n\nexport const packageCompileTscTypes = async (\n entries: string[],\n outDir: string,\n platform: 'node' | 'browser' | 'neutral',\n folder: string = 'src',\n): Promise<number> => {\n const pkg = process.env.INIT_CWD ?? cwd()\n const srcRoot = `${pkg}/${folder}`\n\n const entryNameToTypeName = (entry: string): string => {\n const splitEntryName = entry.split('.')\n const newEntryExtension = 'd.' + splitEntryName.at(-1)\n return [...splitEntryName.slice(0, -1), newEntryExtension].join('.')\n }\n\n const entryNames = entries.map(entry => entry.split(`${folder}/`).at(-1) ?? entry)\n\n await Promise.all(entryNames.map(async (entryName) => {\n await bundleDts(`${srcRoot}/${entryName}`, outDir + '/' + entryNameToTypeName(entryName), platform)\n }))\n return 0\n}\n"],"mappings":";AAAA,SAAS,WAAW;AAEpB,SAAS,cAAc;AACvB,OAAO,SAAS;AAChB,OAAO,mBAAmB;AAE1B,eAAsB,UAAU,WAAmB,YAAoB,UAA0C;AAC/G,QAAM,cAAc,aAAa,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC;AAC/D,QAAM,SAAS,MAAM,OAAO;AAAA,IAC1B,OAAO;AAAA,IACP,SAAS,CAAC,IAAI,GAAG,GAAG,WAAW;AAAA,IAC/B,OAAO,SAAS,MAAM;AAEpB,UAAI,QAAQ,SAAS,yBAA0B;AAC/C,WAAK,OAAO;AAAA,IACd;AAAA,EACF,CAAC;AAED,QAAM,OAAO,MAAM;AAAA,IACjB,MAAM;AAAA,IACN,QAAQ;AAAA,EACV,CAAC;AAED,UAAQ,IAAI,mCAAmC,UAAU,EAAE;AAC7D;AAEO,IAAM,yBAAyB,OACpC,SACA,QACA,UACA,SAAiB,UACG;AACpB,QAAM,MAAM,QAAQ,IAAI,YAAY,IAAI;AACxC,QAAM,UAAU,GAAG,GAAG,IAAI,MAAM;AAEhC,QAAM,sBAAsB,CAAC,UAA0B;AACrD,UAAM,iBAAiB,MAAM,MAAM,GAAG;AACtC,UAAM,oBAAoB,OAAO,eAAe,GAAG,EAAE;AACrD,WAAO,CAAC,GAAG,eAAe,MAAM,GAAG,EAAE,GAAG,iBAAiB,EAAE,KAAK,GAAG;AAAA,EACrE;AAEA,QAAM,aAAa,QAAQ,IAAI,WAAS,MAAM,MAAM,GAAG,MAAM,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK;AAEjF,QAAM,QAAQ,IAAI,WAAW,IAAI,OAAO,cAAc;AACpD,UAAM,UAAU,GAAG,OAAO,IAAI,SAAS,IAAI,SAAS,MAAM,oBAAoB,SAAS,GAAG,QAAQ;AAAA,EACpG,CAAC,CAAC;AACF,SAAO;AACT;","names":[]}
@@ -8,7 +8,7 @@ var getAllInputs = (folder) => {
8
8
  };
9
9
 
10
10
  // src/actions/package/compile/buildEntries.ts
11
- var buildEntries = (folder, entryMode = "single", excludeSpecAndStories = true, verbose = false) => {
11
+ var buildEntries = (folder, entryMode = "single", options, excludeSpecAndStories = true, verbose = false) => {
12
12
  let entries = [];
13
13
  switch (entryMode) {
14
14
  case "platform": {
@@ -19,37 +19,48 @@ var buildEntries = (folder, entryMode = "single", excludeSpecAndStories = true,
19
19
  entries = excludeSpecAndStories ? getAllInputs(folder).filter((entry) => !entry.includes(".spec.") && !entry.includes(".stories.")) : getAllInputs(folder);
20
20
  break;
21
21
  }
22
+ case "custom": {
23
+ entries = [];
24
+ break;
25
+ }
22
26
  default: {
23
27
  entries = [`${folder}/index.ts`];
24
28
  break;
25
29
  }
26
30
  }
31
+ if (typeof options !== "boolean" && Array.isArray(options?.entry)) {
32
+ entries.push(...options.entry);
33
+ }
27
34
  if (verbose) console.log(`buildEntries [${entryMode}] ${entries.length}`);
28
35
  return entries;
29
36
  };
30
37
 
31
- // src/lib/loadConfig.ts
32
- import chalk from "chalk";
33
- import { cosmiconfig } from "cosmiconfig";
34
- import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
35
- import deepmerge from "deepmerge";
36
- var config;
37
- var loadConfig = async (params) => {
38
- if (config) {
39
- return deepmerge(config, params ?? {});
38
+ // src/actions/package/compile/deepMerge.ts
39
+ function deepMerge(target, source) {
40
+ if (!source || typeof source !== "object") return target;
41
+ for (const key of Object.keys(source)) {
42
+ if (typeof source[key] === "object" && source[key] !== null && !Array.isArray(source[key])) {
43
+ if (!target[key] || typeof target[key] !== "object") {
44
+ target[key] = {};
45
+ }
46
+ deepMerge(target[key], source[key]);
47
+ } else {
48
+ target[key] = source[key];
49
+ }
40
50
  }
41
- const cosmicConfigResult = await cosmiconfig("xy", { cache: true, loaders: { ".ts": TypeScriptLoader() } }).search();
42
- config = cosmicConfigResult?.config;
43
- const configFilePath = cosmicConfigResult?.filepath;
44
- if (configFilePath) {
45
- console.log(chalk.gray(`Loading config from ${configFilePath}`));
51
+ return target;
52
+ }
53
+ function deepMergeObjects(objects) {
54
+ const result = {};
55
+ for (const obj of objects) {
56
+ deepMerge(result, obj);
46
57
  }
47
- return deepmerge(config, params ?? {});
48
- };
58
+ return result;
59
+ }
49
60
 
50
- // src/actions/package/compile/packageCompileTscTypes.ts
61
+ // src/actions/package/compile/packageCompileTsc.ts
51
62
  import { cwd } from "process";
52
- import chalk2 from "chalk";
63
+ import chalk from "chalk";
53
64
  import { createProgramFromConfig } from "tsc-prog";
54
65
  import {
55
66
  DiagnosticCategory,
@@ -60,57 +71,57 @@ import {
60
71
 
61
72
  // src/actions/package/compile/getCompilerOptions.ts
62
73
  import { createRequire } from "module";
63
- import deepmerge2 from "deepmerge";
74
+ import deepmerge from "deepmerge";
64
75
  import {
65
76
  findConfigFile,
66
77
  readConfigFile,
67
78
  sys
68
79
  } from "typescript";
69
- var getNested = (config2) => {
70
- if (config2.extends) {
80
+ var getNested = (config) => {
81
+ if (config.extends) {
71
82
  const require2 = createRequire(import.meta.url);
72
- const opts = require2(config2.extends);
73
- return deepmerge2(getNested(opts), config2.compilerOptions ?? {});
83
+ const opts = require2(config.extends);
84
+ return deepmerge(getNested(opts), config.compilerOptions ?? {});
74
85
  }
75
- return config2.compilerOptions;
86
+ return config.compilerOptions;
76
87
  };
77
88
  var getCompilerOptionsJSONFollowExtends = (filename) => {
78
- const config2 = readConfigFile(filename, sys.readFile).config;
79
- return getNested(config2);
89
+ const config = readConfigFile(filename, sys.readFile).config;
90
+ return getNested(config);
80
91
  };
81
92
  var getCompilerOptions = (options = {}, tsconfig = "tsconfig.json") => {
82
93
  const configFileName = findConfigFile("./", sys.fileExists, tsconfig);
83
94
  const configFileCompilerOptions = (configFileName ? getCompilerOptionsJSONFollowExtends(configFileName) : void 0) ?? {};
84
- return deepmerge2(configFileCompilerOptions, options);
95
+ return deepmerge(configFileCompilerOptions, options);
85
96
  };
86
97
 
87
- // src/actions/package/compile/packageCompileTscTypes.ts
88
- var packageCompileTscTypes = (folder = "src", config2 = {}, compilerOptionsParam) => {
98
+ // src/actions/package/compile/packageCompileTsc.ts
99
+ var packageCompileTsc = (entries, folder = "src", config = {}, compilerOptionsParam) => {
89
100
  const pkg = process.env.INIT_CWD ?? cwd();
90
- const verbose = config2?.verbose ?? false;
101
+ const verbose = config?.verbose ?? false;
91
102
  const compilerOptions = {
92
103
  ...getCompilerOptions({
93
- emitDeclarationOnly: true,
94
- outDir: config2.compile?.tsup?.options?.outDir ?? "dist/types",
104
+ outDir: "dist/types",
95
105
  removeComments: false,
96
106
  skipDefaultLibCheck: true,
97
107
  skipLibCheck: true,
98
108
  sourceMap: false
99
109
  }),
100
110
  ...compilerOptionsParam,
101
- emitDeclarationOnly: true,
102
- noEmit: false
111
+ emitDeclarationOnly: false,
112
+ noEmit: true
103
113
  };
104
- const validTsExt = [".ts", ".tsx", ".d.ts", ".cts", ".d.cts", ".mts", ".d.mts"];
105
- const excludes = [".stories.", ".spec.", "/stories/", "/spec/"];
106
- const files = buildEntries(folder, "all", verbose).filter((file) => validTsExt.find((ext) => file.endsWith(ext)) && !excludes.some((exclude) => file.includes(exclude)));
107
- console.log(chalk2.green(`Compiling Types ${pkg}: ${files.length}`));
108
- if (files.length > 0) {
114
+ console.log(chalk.green(`Validating Files: ${entries.length}`));
115
+ if (verbose) {
116
+ for (const entry of entries) {
117
+ console.log(chalk.grey(`Validating: ${entry}`));
118
+ }
119
+ }
120
+ if (entries.length > 0) {
109
121
  const program = createProgramFromConfig({
110
122
  basePath: pkg ?? cwd(),
111
123
  compilerOptions,
112
- exclude: ["build", "dist", "docs", "**/*.spec.*", "**/*.stories.*", "src/**/spec/**/*"],
113
- files
124
+ files: entries
114
125
  });
115
126
  const diagnostics = getPreEmitDiagnostics(program);
116
127
  if (diagnostics.length > 0) {
@@ -130,102 +141,54 @@ var packageCompileTscTypes = (folder = "src", config2 = {}, compilerOptionsParam
130
141
  return 0;
131
142
  };
132
143
 
133
- // src/actions/package/compile/compileTypes.ts
134
- var packageCompileTypes = async (inConfig = {}) => {
135
- const config2 = await loadConfig(inConfig);
136
- return packageCompileTscTypes(void 0, config2);
137
- };
138
-
139
- // src/actions/package/compile/deepMerge.ts
140
- function deepMerge(target, source) {
141
- if (!source || typeof source !== "object") return target;
142
- for (const key of Object.keys(source)) {
143
- if (typeof source[key] === "object" && source[key] !== null && !Array.isArray(source[key])) {
144
- if (!target[key] || typeof target[key] !== "object") {
145
- target[key] = {};
146
- }
147
- deepMerge(target[key], source[key]);
148
- } else {
149
- target[key] = source[key];
144
+ // src/actions/package/compile/packageCompileTscTypes.ts
145
+ import { cwd as cwd2 } from "process";
146
+ import { rollup } from "rollup";
147
+ import dts from "rollup-plugin-dts";
148
+ import nodeExternals from "rollup-plugin-node-externals";
149
+ async function bundleDts(inputPath, outputPath, platform) {
150
+ const nodePlugIns = platform === "node" ? [nodeExternals()] : [];
151
+ const bundle = await rollup({
152
+ input: inputPath,
153
+ plugins: [dts(), ...nodePlugIns],
154
+ onwarn(warning, warn) {
155
+ if (warning.code === "UNUSED_EXTERNAL_IMPORT") return;
156
+ warn(warning);
150
157
  }
151
- }
152
- return target;
153
- }
154
- function deepMergeObjects(objects) {
155
- const result = {};
156
- for (const obj of objects) {
157
- deepMerge(result, obj);
158
- }
159
- return result;
158
+ });
159
+ await bundle.write({
160
+ file: outputPath,
161
+ format: "es"
162
+ });
163
+ console.log(`Bundled declarations written to ${outputPath}`);
160
164
  }
161
-
162
- // src/actions/package/compile/packageCompileTsc.ts
163
- import { cwd as cwd2 } from "process";
164
- import chalk3 from "chalk";
165
- import { createProgramFromConfig as createProgramFromConfig2 } from "tsc-prog";
166
- import {
167
- DiagnosticCategory as DiagnosticCategory2,
168
- formatDiagnosticsWithColorAndContext as formatDiagnosticsWithColorAndContext2,
169
- getPreEmitDiagnostics as getPreEmitDiagnostics2,
170
- sys as sys3
171
- } from "typescript";
172
- var packageCompileTsc = (folder = "src", config2 = {}, compilerOptionsParam) => {
165
+ var packageCompileTscTypes = async (entries, outDir, platform, folder = "src") => {
173
166
  const pkg = process.env.INIT_CWD ?? cwd2();
174
- const verbose = config2?.verbose ?? false;
175
- const compilerOptions = {
176
- ...getCompilerOptions({
177
- outDir: "dist/types",
178
- removeComments: false,
179
- skipDefaultLibCheck: true,
180
- skipLibCheck: true,
181
- sourceMap: false
182
- }),
183
- ...compilerOptionsParam,
184
- emitDeclarationOnly: false,
185
- noEmit: true
167
+ const srcRoot = `${pkg}/${folder}`;
168
+ const entryNameToTypeName = (entry) => {
169
+ const splitEntryName = entry.split(".");
170
+ const newEntryExtension = "d." + splitEntryName.at(-1);
171
+ return [...splitEntryName.slice(0, -1), newEntryExtension].join(".");
186
172
  };
187
- const validTsExt = [".ts", ".tsx", ".d.ts", ".cts", ".d.cts", ".mts", ".d.mts"];
188
- const includes = [".stories.", ".spec.", ".d.ts", ".d.cts", ".d.mts"];
189
- const files = buildEntries(folder, "all", verbose).filter((file) => validTsExt.find((ext) => file.endsWith(ext)) && includes.find((include) => file.includes(include)));
190
- console.log(chalk3.green(`Compiling Files ${pkg}: ${files.length}`));
191
- if (files.length > 0) {
192
- const program = createProgramFromConfig2({
193
- basePath: pkg ?? cwd2(),
194
- compilerOptions,
195
- exclude: ["dist", "docs"],
196
- files
197
- });
198
- const diagnostics = getPreEmitDiagnostics2(program);
199
- if (diagnostics.length > 0) {
200
- const formattedDiagnostics = formatDiagnosticsWithColorAndContext2(
201
- diagnostics,
202
- {
203
- getCanonicalFileName: (fileName) => fileName,
204
- getCurrentDirectory: () => folder,
205
- getNewLine: () => sys3.newLine
206
- }
207
- );
208
- console.error(formattedDiagnostics);
209
- }
210
- program.emit();
211
- return diagnostics.reduce((acc, diag) => acc + (diag.category === DiagnosticCategory2.Error ? 1 : 0), 0);
212
- }
173
+ const entryNames = entries.map((entry) => entry.split(`${folder}/`).at(-1) ?? entry);
174
+ await Promise.all(entryNames.map(async (entryName) => {
175
+ await bundleDts(`${srcRoot}/${entryName}`, outDir + "/" + entryNameToTypeName(entryName), platform);
176
+ }));
213
177
  return 0;
214
178
  };
215
179
 
216
180
  // src/actions/package/compile/packageCompileTsup.ts
217
- var compileFolder = async (folder, entryMode = "single", options, verbose) => {
181
+ var compileFolder = async (folder, entries, options, verbose) => {
218
182
  const outDir = options?.outDir ?? "dist";
219
183
  if (verbose) {
220
184
  console.log(`compileFolder [${folder}]`);
221
185
  }
222
- const entry = buildEntries(folder, entryMode);
223
186
  const optionsResult = defineConfig({
224
187
  bundle: true,
225
188
  cjsInterop: true,
226
189
  clean: true,
227
190
  dts: false,
228
- entry,
191
+ entry: entries,
229
192
  format: ["esm"],
230
193
  outDir,
231
194
  silent: true,
@@ -234,6 +197,11 @@ var compileFolder = async (folder, entryMode = "single", options, verbose) => {
234
197
  tsconfig: "tsconfig.json",
235
198
  ...options
236
199
  });
200
+ const validationResult = packageCompileTsc(entries);
201
+ if (validationResult !== 0) {
202
+ console.error(`Compile:Validation had ${validationResult} errors`);
203
+ return validationResult;
204
+ }
237
205
  const optionsList = (await Promise.all(
238
206
  (Array.isArray(optionsResult) ? optionsResult : [optionsResult]).flatMap(async (options2) => {
239
207
  const result = typeof options2 === "function" ? await options2({}) : [options2];
@@ -247,6 +215,7 @@ var compileFolder = async (folder, entryMode = "single", options, verbose) => {
247
215
  if (verbose) {
248
216
  console.log(`TSUP:build:stop [${folder}]`);
249
217
  }
218
+ await packageCompileTscTypes(entries, outDir, options?.platform ?? "neutral", folder);
250
219
  return 0;
251
220
  };
252
221
  var tsupOptions = (options = []) => {
@@ -270,30 +239,22 @@ var tsupOptions = (options = []) => {
270
239
  };
271
240
  return deepMergeObjects([standardOptions, ...options]);
272
241
  };
273
- var packageCompileTsup = async (config2) => {
274
- const compile = config2?.compile;
275
- const verbose = config2?.verbose ?? false;
242
+ var packageCompileTsup = async (config) => {
243
+ const compile = config?.compile;
244
+ const verbose = config?.verbose ?? false;
276
245
  if (verbose) {
277
246
  console.log(`Compiling with TSUP [Depth: ${compile?.depth}]`);
278
247
  }
279
248
  const compileForNode = compile?.node ?? { src: {} };
280
249
  const compileForBrowser = compile?.browser ?? { src: {} };
281
250
  const compileForNeutral = compile?.neutral ?? { src: {} };
282
- if (verbose) {
283
- console.log("Calling packageCompileTscTypes");
284
- }
285
- let errors = await packageCompileTypes(config2);
286
- errors = errors + packageCompileTsc(void 0, config2);
287
- if (errors > 0) {
288
- return errors;
289
- }
290
251
  return (await Promise.all(
291
252
  Object.entries(compileForNode).map(async ([folder, options]) => {
292
253
  const optionsObject = typeof options === "object" ? options : {};
293
254
  const inEsBuildOptions = typeof compile?.node?.esbuildOptions === "object" ? compile?.node?.esbuildOptions : {};
294
255
  return typeof folder === "string" ? await compileFolder(
295
256
  folder,
296
- compile?.entryMode,
257
+ buildEntries(folder, compile?.entryMode, options, true, verbose),
297
258
  tsupOptions([
298
259
  inEsBuildOptions,
299
260
  compile?.tsup?.options ?? {},
@@ -309,7 +270,7 @@ var packageCompileTsup = async (config2) => {
309
270
  const inEsBuildOptions = typeof compile?.browser?.esbuildOptions === "object" ? compile?.browser?.esbuildOptions : {};
310
271
  return typeof folder === "string" ? await compileFolder(
311
272
  folder,
312
- compile?.entryMode,
273
+ buildEntries(folder, compile?.entryMode, options, true, verbose),
313
274
  tsupOptions([
314
275
  inEsBuildOptions,
315
276
  compile?.tsup?.options ?? {},
@@ -325,7 +286,7 @@ var packageCompileTsup = async (config2) => {
325
286
  const inEsBuildOptions = typeof compile?.neutral?.esbuildOptions === "object" ? compile?.neutral?.esbuildOptions : {};
326
287
  return typeof folder === "string" ? await compileFolder(
327
288
  folder,
328
- compile?.entryMode,
289
+ buildEntries(folder, compile?.entryMode, options, true, verbose),
329
290
  tsupOptions([
330
291
  inEsBuildOptions,
331
292
  compile?.tsup?.options ?? {},