@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.
- package/dist/actions/index.mjs +110 -130
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/package/compile/buildEntries.mjs +8 -1
- package/dist/actions/package/compile/buildEntries.mjs.map +1 -1
- package/dist/actions/package/compile/compile.mjs +87 -107
- package/dist/actions/package/compile/compile.mjs.map +1 -1
- package/dist/actions/package/compile/index.mjs +88 -108
- package/dist/actions/package/compile/index.mjs.map +1 -1
- package/dist/actions/package/compile/packageCompileTsc.mjs +9 -35
- package/dist/actions/package/compile/packageCompileTsc.mjs.map +1 -1
- package/dist/actions/package/compile/packageCompileTscTypes.mjs +29 -102
- package/dist/actions/package/compile/packageCompileTscTypes.mjs.map +1 -1
- package/dist/actions/package/compile/packageCompileTsup.mjs +96 -135
- package/dist/actions/package/compile/packageCompileTsup.mjs.map +1 -1
- package/dist/actions/package/index.mjs +100 -120
- package/dist/actions/package/index.mjs.map +1 -1
- package/dist/actions/package/recompile.mjs +87 -107
- package/dist/actions/package/recompile.mjs.map +1 -1
- package/dist/bin/package/build-only.mjs +89 -109
- package/dist/bin/package/build-only.mjs.map +1 -1
- package/dist/bin/package/build.mjs +89 -109
- package/dist/bin/package/build.mjs.map +1 -1
- package/dist/bin/package/compile-only.mjs +89 -109
- package/dist/bin/package/compile-only.mjs.map +1 -1
- package/dist/bin/package/compile-tsup.mjs +101 -140
- package/dist/bin/package/compile-tsup.mjs.map +1 -1
- package/dist/bin/package/compile.mjs +89 -109
- package/dist/bin/package/compile.mjs.map +1 -1
- package/dist/bin/package/recompile.mjs +89 -109
- package/dist/bin/package/recompile.mjs.map +1 -1
- package/dist/index.d.ts +24 -7
- package/dist/index.mjs +122 -142
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -5
- package/dist/actions/package/compile/compileTypes.mjs +0 -138
- package/dist/actions/package/compile/compileTypes.mjs.map +0 -1
- package/dist/bin/package/compile-types.mjs +0 -150
- 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
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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"
|
|
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/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
48
|
-
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
49
60
|
|
|
50
|
-
// src/actions/package/compile/
|
|
61
|
+
// src/actions/package/compile/packageCompileTsc.ts
|
|
51
62
|
import { cwd } from "process";
|
|
52
|
-
import
|
|
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
|
|
74
|
+
import deepmerge from "deepmerge";
|
|
64
75
|
import {
|
|
65
76
|
findConfigFile,
|
|
66
77
|
readConfigFile,
|
|
67
78
|
sys
|
|
68
79
|
} from "typescript";
|
|
69
|
-
var getNested = (
|
|
70
|
-
if (
|
|
80
|
+
var getNested = (config) => {
|
|
81
|
+
if (config.extends) {
|
|
71
82
|
const require2 = createRequire(import.meta.url);
|
|
72
|
-
const opts = require2(
|
|
73
|
-
return
|
|
83
|
+
const opts = require2(config.extends);
|
|
84
|
+
return deepmerge(getNested(opts), config.compilerOptions ?? {});
|
|
74
85
|
}
|
|
75
|
-
return
|
|
86
|
+
return config.compilerOptions;
|
|
76
87
|
};
|
|
77
88
|
var getCompilerOptionsJSONFollowExtends = (filename) => {
|
|
78
|
-
const
|
|
79
|
-
return getNested(
|
|
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
|
|
95
|
+
return deepmerge(configFileCompilerOptions, options);
|
|
85
96
|
};
|
|
86
97
|
|
|
87
|
-
// src/actions/package/compile/
|
|
88
|
-
var
|
|
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 =
|
|
101
|
+
const verbose = config?.verbose ?? false;
|
|
91
102
|
const compilerOptions = {
|
|
92
103
|
...getCompilerOptions({
|
|
93
|
-
|
|
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:
|
|
102
|
-
noEmit:
|
|
111
|
+
emitDeclarationOnly: false,
|
|
112
|
+
noEmit: true
|
|
103
113
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
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/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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,
|
|
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 (
|
|
274
|
-
const compile =
|
|
275
|
-
const verbose =
|
|
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 ?? {},
|