@xylabs/ts-scripts-yarn3 3.0.2 → 3.0.4
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.
|
@@ -42,35 +42,63 @@ var import_loadPackageConfig = require("../../loadPackageConfig");
|
|
|
42
42
|
var import_publint = require("./publint");
|
|
43
43
|
const rollItUp = async (format, ext, subDir) => {
|
|
44
44
|
const input = await getInputs(subDir);
|
|
45
|
+
const tsPlugIn = (0, import_plugin_typescript.default)({
|
|
46
|
+
baseUrl: "src",
|
|
47
|
+
declaration: !subDir,
|
|
48
|
+
declarationMap: !subDir,
|
|
49
|
+
emitDeclarationOnly: false,
|
|
50
|
+
esModuleInterop: true,
|
|
51
|
+
exclude: ["**/*.spec.*", "dist", "docs", "node_modules", "packages"],
|
|
52
|
+
outDir: subDir ? `dist/${subDir}` : "dist",
|
|
53
|
+
rootDir: "src",
|
|
54
|
+
tsconfig: "tsconfig.json"
|
|
55
|
+
});
|
|
56
|
+
const errors = [];
|
|
57
|
+
const warnings = [];
|
|
58
|
+
const infos = [];
|
|
59
|
+
const debugs = [];
|
|
60
|
+
const options = {
|
|
61
|
+
input: input.map((file) => `./src/${file}`),
|
|
62
|
+
logLevel: "warn",
|
|
63
|
+
onLog: (level, log, defaultHandler) => {
|
|
64
|
+
switch (level) {
|
|
65
|
+
case "warn": {
|
|
66
|
+
warnings.push(log);
|
|
67
|
+
console.warn(import_chalk.default.yellow(JSON.stringify(log, null, 2)));
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case "info": {
|
|
71
|
+
infos.push(log);
|
|
72
|
+
console.info(import_chalk.default.white(JSON.stringify(log, null, 2)));
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case "debug": {
|
|
76
|
+
debugs.push(log);
|
|
77
|
+
console.debug(import_chalk.default.gray(JSON.stringify(log, null, 2)));
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
default: {
|
|
81
|
+
errors.push(log);
|
|
82
|
+
console.error(import_chalk.default.red(JSON.stringify(log, null, 2)));
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
console.log(`Log: ${level}: ${log.cause}`);
|
|
87
|
+
return defaultHandler(level, log);
|
|
88
|
+
},
|
|
89
|
+
plugins: [(0, import_plugin_commonjs.default)(), (0, import_rollup_plugin_exclude_dependencies_from_bundle.default)(), (0, import_rollup_plugin_node_externals.default)(), tsPlugIn]
|
|
90
|
+
};
|
|
91
|
+
const outputOptions = {
|
|
92
|
+
dir: subDir ? `dist/${subDir}` : "dist",
|
|
93
|
+
dynamicImportInCjs: true,
|
|
94
|
+
entryFileNames: (chunkInfo) => `${chunkInfo.name}.${ext}`,
|
|
95
|
+
format,
|
|
96
|
+
sourcemap: true
|
|
97
|
+
};
|
|
45
98
|
if (input.length) {
|
|
46
|
-
await (await (0, import_rollup.rollup)(
|
|
47
|
-
input: input.map((file) => `./src/${file}`),
|
|
48
|
-
logLevel: "warn",
|
|
49
|
-
perf: true,
|
|
50
|
-
plugins: [
|
|
51
|
-
(0, import_plugin_commonjs.default)(),
|
|
52
|
-
(0, import_rollup_plugin_exclude_dependencies_from_bundle.default)(),
|
|
53
|
-
(0, import_rollup_plugin_node_externals.default)(),
|
|
54
|
-
(0, import_plugin_typescript.default)({
|
|
55
|
-
baseUrl: "./src",
|
|
56
|
-
declaration: !subDir,
|
|
57
|
-
declarationMap: !subDir,
|
|
58
|
-
emitDeclarationOnly: false,
|
|
59
|
-
esModuleInterop: true,
|
|
60
|
-
exclude: ["**/*.spec.*", "dist", "docs"],
|
|
61
|
-
outDir: subDir ? `dist/${subDir}` : "dist",
|
|
62
|
-
rootDir: "src",
|
|
63
|
-
tsconfig: "tsconfig.json"
|
|
64
|
-
})
|
|
65
|
-
]
|
|
66
|
-
})).write({
|
|
67
|
-
dir: subDir ? `dist/${subDir}` : "dist",
|
|
68
|
-
dynamicImportInCjs: true,
|
|
69
|
-
entryFileNames: (chunkInfo) => `${chunkInfo.name}.${ext}`,
|
|
70
|
-
format,
|
|
71
|
-
sourcemap: true
|
|
72
|
-
});
|
|
99
|
+
await (await (0, import_rollup.rollup)(options)).write(outputOptions);
|
|
73
100
|
}
|
|
101
|
+
return errors.length + warnings.length;
|
|
74
102
|
};
|
|
75
103
|
const getInputs = async (subDir) => {
|
|
76
104
|
return (await (0, import_promises.readdir)(subDir ? `src/${subDir}` : "src", { recursive: false })).filter((file) => (file.endsWith(".ts") || file.endsWith(".tsx")) && !file.endsWith("d.ts") && !file.endsWith("spec.ts")).map((file) => subDir ? `${subDir}/${file}` : file);
|
|
@@ -101,10 +129,9 @@ const buildIt = async (pkg) => {
|
|
|
101
129
|
const pkgType = pkg.type ?? "commonjs";
|
|
102
130
|
const esmExt = pkgType === "module" ? "js" : "mjs";
|
|
103
131
|
const cjsExt = pkgType === "commonjs" ? "js" : "cjs";
|
|
104
|
-
await Promise.all(
|
|
132
|
+
const rollupResult = await Promise.all(
|
|
105
133
|
inputDirs.map(async (inputDir) => {
|
|
106
|
-
await rollItUp("esm", esmExt, inputDir);
|
|
107
|
-
await rollItUp("cjs", cjsExt, inputDir);
|
|
134
|
+
return await rollItUp("esm", esmExt, inputDir) + await rollItUp("cjs", cjsExt, inputDir);
|
|
108
135
|
})
|
|
109
136
|
);
|
|
110
137
|
const distTypeFiles = await getDistTypeFiles();
|
|
@@ -119,7 +146,7 @@ const buildIt = async (pkg) => {
|
|
|
119
146
|
await (0, import_promises.copyFile)(file, file.replace("d.ts.map", "d.mts.map"));
|
|
120
147
|
})
|
|
121
148
|
);
|
|
122
|
-
return 0;
|
|
149
|
+
return rollupResult.reduce((prev, item) => prev + item, 0);
|
|
123
150
|
};
|
|
124
151
|
const packageCompile = async ({ publint = true, verbose } = { verbose: false }) => {
|
|
125
152
|
const pkgName = process.env.npm_package_name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/package/compile.ts"],"sourcesContent":["import commonjs from '@rollup/plugin-commonjs'\nimport typescript from '@rollup/plugin-typescript'\nimport chalk from 'chalk'\nimport { copyFile, readdir } from 'fs/promises'\nimport { rollup } from 'rollup'\nimport externalDeps from 'rollup-plugin-exclude-dependencies-from-bundle'\nimport nodeExternals from 'rollup-plugin-node-externals'\n\nimport { loadPackageConfig, PackageJsonEx } from '../../loadPackageConfig'\nimport { packagePublint } from './publint'\n\nexport interface CompilePackageParams {\n publint?: boolean\n verbose?: boolean\n}\n\nconst rollItUp = async (format: 'cjs' | 'esm', ext: string, subDir?: string) => {\n const input = await getInputs(subDir)\n
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/package/compile.ts"],"sourcesContent":["import commonjs from '@rollup/plugin-commonjs'\nimport typescript from '@rollup/plugin-typescript'\nimport chalk from 'chalk'\nimport { copyFile, readdir } from 'fs/promises'\nimport { OutputOptions, rollup, RollupLog, RollupOptions, watch } from 'rollup'\nimport externalDeps from 'rollup-plugin-exclude-dependencies-from-bundle'\nimport nodeExternals from 'rollup-plugin-node-externals'\n\nimport { loadPackageConfig, PackageJsonEx } from '../../loadPackageConfig'\nimport { packagePublint } from './publint'\n\nexport interface CompilePackageParams {\n publint?: boolean\n verbose?: boolean\n}\n\nconst rollItUp = async (format: 'cjs' | 'esm', ext: string, subDir?: string) => {\n const input = await getInputs(subDir)\n const tsPlugIn = typescript({\n baseUrl: 'src',\n declaration: !subDir,\n declarationMap: !subDir,\n emitDeclarationOnly: false,\n esModuleInterop: true,\n exclude: ['**/*.spec.*', 'dist', 'docs', 'node_modules', 'packages'],\n outDir: subDir ? `dist/${subDir}` : 'dist',\n rootDir: 'src',\n tsconfig: 'tsconfig.json',\n })\n\n const errors: RollupLog[] = []\n const warnings: RollupLog[] = []\n const infos: RollupLog[] = []\n const debugs: RollupLog[] = []\n\n const options: RollupOptions = {\n input: input.map((file) => `./src/${file}`),\n logLevel: 'warn',\n onLog: (level, log, defaultHandler) => {\n switch (level) {\n case 'warn': {\n warnings.push(log)\n console.warn(chalk.yellow(JSON.stringify(log, null, 2)))\n break\n }\n case 'info': {\n infos.push(log)\n console.info(chalk.white(JSON.stringify(log, null, 2)))\n break\n }\n case 'debug': {\n debugs.push(log)\n console.debug(chalk.gray(JSON.stringify(log, null, 2)))\n break\n }\n default: {\n errors.push(log)\n console.error(chalk.red(JSON.stringify(log, null, 2)))\n break\n }\n }\n console.log(`Log: ${level}: ${log.cause}`)\n return defaultHandler(level, log)\n },\n plugins: [commonjs(), externalDeps(), nodeExternals(), tsPlugIn],\n }\n\n const outputOptions: OutputOptions = {\n dir: subDir ? `dist/${subDir}` : 'dist',\n dynamicImportInCjs: true,\n entryFileNames: (chunkInfo) => `${chunkInfo.name}.${ext}`,\n format,\n sourcemap: true,\n }\n\n if (input.length) {\n await (await rollup(options)).write(outputOptions)\n }\n\n return errors.length + warnings.length\n}\n\nconst getInputs = async (subDir?: string) => {\n return (await readdir(subDir ? `src/${subDir}` : 'src', { recursive: false }))\n .filter((file) => (file.endsWith('.ts') || file.endsWith('.tsx')) && !file.endsWith('d.ts') && !file.endsWith('spec.ts'))\n .map((file) => (subDir ? `${subDir}/${file}` : file))\n}\n\nconst getInputDirs = async () => {\n return [\n undefined,\n ...(await readdir('src', { recursive: true, withFileTypes: true }))\n .filter((file) => file.isDirectory())\n .map((file) => {\n const pathParts = file.path.split('/')\n pathParts.shift()\n if (pathParts.length) {\n const root = pathParts.join('/')\n return `${root}/${file.name}`\n } else {\n return file.name\n }\n }),\n ]\n}\n\nconst getDistTypeFiles = async () => {\n return (await readdir('dist', { recursive: true })).filter((file) => file.endsWith('d.ts')).map((file) => `dist/${file}`)\n}\n\nconst getDistTypeMapFiles = async () => {\n return (await readdir('dist', { recursive: true })).filter((file) => file.endsWith('d.ts.map')).map((file) => `dist/${file}`)\n}\n\nconst buildIt = async (pkg: PackageJsonEx) => {\n const inputDirs = await getInputDirs()\n\n const pkgType = pkg.type ?? 'commonjs'\n\n const esmExt = pkgType === 'module' ? 'js' : 'mjs'\n const cjsExt = pkgType === 'commonjs' ? 'js' : 'cjs'\n\n const rollupResult = await Promise.all(\n inputDirs.map(async (inputDir) => {\n return await rollItUp('esm', esmExt, inputDir) + await rollItUp('cjs', cjsExt, inputDir)\n }),\n )\n\n //hybrid packages want two copies of the types\n const distTypeFiles = await getDistTypeFiles()\n await Promise.all(\n distTypeFiles.map(async (file) => {\n await copyFile(file, file.replace('d.ts', 'd.mts'))\n }),\n )\n\n const distTypeMapFiles = await getDistTypeMapFiles()\n await Promise.all(\n distTypeMapFiles.map(async (file) => {\n await copyFile(file, file.replace('d.ts.map', 'd.mts.map'))\n }),\n )\n\n return rollupResult.reduce((prev, item) => prev + item, 0)\n}\n\nexport const packageCompile = async ({ publint = true, verbose }: CompilePackageParams = { verbose: false }) => {\n const pkgName = process.env.npm_package_name\n if (verbose) {\n console.log(chalk.green(`Compiling ${pkgName} Start`))\n }\n const result = (await buildIt(await loadPackageConfig())) + (publint ? await packagePublint() : 0)\n if (result) {\n const input = await getInputs()\n console.log(`Inputs: ${JSON.stringify(input, null, 2)}`)\n console.error(chalk.red(`Compiling ${pkgName} Failed [${result}]`))\n } else if (verbose) {\n console.log(chalk.green(`Compiling ${pkgName} Done`))\n }\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAqB;AACrB,+BAAuB;AACvB,mBAAkB;AAClB,sBAAkC;AAClC,oBAAuE;AACvE,4DAAyB;AACzB,0CAA0B;AAE1B,+BAAiD;AACjD,qBAA+B;AAO/B,MAAM,WAAW,OAAO,QAAuB,KAAa,WAAoB;AAC9E,QAAM,QAAQ,MAAM,UAAU,MAAM;AACpC,QAAM,eAAW,yBAAAA,SAAW;AAAA,IAC1B,SAAS;AAAA,IACT,aAAa,CAAC;AAAA,IACd,gBAAgB,CAAC;AAAA,IACjB,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,IACjB,SAAS,CAAC,eAAe,QAAQ,QAAQ,gBAAgB,UAAU;A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;AAC9B,YAAQ,IAAI,WAAW,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC,EAAE;AACvD,YAAQ,MAAM,aAAAA,QAAM,IAAI,aAAa,OAAO,YAAY,MAAM,GAAG,CAAC;AAAA,EACpE,WAAW,SAAS;AAClB,YAAQ,IAAI,aAAAA,QAAM,MAAM,aAAa,OAAO,OAAO,CAAC;AAAA,EACtD;AACA,SAAO;AACT;","names":["typescript","chalk","commonjs","externalDeps","nodeExternals"]}
|
|
@@ -9,35 +9,63 @@ import { loadPackageConfig } from "../../loadPackageConfig";
|
|
|
9
9
|
import { packagePublint } from "./publint";
|
|
10
10
|
const rollItUp = async (format, ext, subDir) => {
|
|
11
11
|
const input = await getInputs(subDir);
|
|
12
|
+
const tsPlugIn = typescript({
|
|
13
|
+
baseUrl: "src",
|
|
14
|
+
declaration: !subDir,
|
|
15
|
+
declarationMap: !subDir,
|
|
16
|
+
emitDeclarationOnly: false,
|
|
17
|
+
esModuleInterop: true,
|
|
18
|
+
exclude: ["**/*.spec.*", "dist", "docs", "node_modules", "packages"],
|
|
19
|
+
outDir: subDir ? `dist/${subDir}` : "dist",
|
|
20
|
+
rootDir: "src",
|
|
21
|
+
tsconfig: "tsconfig.json"
|
|
22
|
+
});
|
|
23
|
+
const errors = [];
|
|
24
|
+
const warnings = [];
|
|
25
|
+
const infos = [];
|
|
26
|
+
const debugs = [];
|
|
27
|
+
const options = {
|
|
28
|
+
input: input.map((file) => `./src/${file}`),
|
|
29
|
+
logLevel: "warn",
|
|
30
|
+
onLog: (level, log, defaultHandler) => {
|
|
31
|
+
switch (level) {
|
|
32
|
+
case "warn": {
|
|
33
|
+
warnings.push(log);
|
|
34
|
+
console.warn(chalk.yellow(JSON.stringify(log, null, 2)));
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case "info": {
|
|
38
|
+
infos.push(log);
|
|
39
|
+
console.info(chalk.white(JSON.stringify(log, null, 2)));
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case "debug": {
|
|
43
|
+
debugs.push(log);
|
|
44
|
+
console.debug(chalk.gray(JSON.stringify(log, null, 2)));
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
default: {
|
|
48
|
+
errors.push(log);
|
|
49
|
+
console.error(chalk.red(JSON.stringify(log, null, 2)));
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
console.log(`Log: ${level}: ${log.cause}`);
|
|
54
|
+
return defaultHandler(level, log);
|
|
55
|
+
},
|
|
56
|
+
plugins: [commonjs(), externalDeps(), nodeExternals(), tsPlugIn]
|
|
57
|
+
};
|
|
58
|
+
const outputOptions = {
|
|
59
|
+
dir: subDir ? `dist/${subDir}` : "dist",
|
|
60
|
+
dynamicImportInCjs: true,
|
|
61
|
+
entryFileNames: (chunkInfo) => `${chunkInfo.name}.${ext}`,
|
|
62
|
+
format,
|
|
63
|
+
sourcemap: true
|
|
64
|
+
};
|
|
12
65
|
if (input.length) {
|
|
13
|
-
await (await rollup(
|
|
14
|
-
input: input.map((file) => `./src/${file}`),
|
|
15
|
-
logLevel: "warn",
|
|
16
|
-
perf: true,
|
|
17
|
-
plugins: [
|
|
18
|
-
commonjs(),
|
|
19
|
-
externalDeps(),
|
|
20
|
-
nodeExternals(),
|
|
21
|
-
typescript({
|
|
22
|
-
baseUrl: "./src",
|
|
23
|
-
declaration: !subDir,
|
|
24
|
-
declarationMap: !subDir,
|
|
25
|
-
emitDeclarationOnly: false,
|
|
26
|
-
esModuleInterop: true,
|
|
27
|
-
exclude: ["**/*.spec.*", "dist", "docs"],
|
|
28
|
-
outDir: subDir ? `dist/${subDir}` : "dist",
|
|
29
|
-
rootDir: "src",
|
|
30
|
-
tsconfig: "tsconfig.json"
|
|
31
|
-
})
|
|
32
|
-
]
|
|
33
|
-
})).write({
|
|
34
|
-
dir: subDir ? `dist/${subDir}` : "dist",
|
|
35
|
-
dynamicImportInCjs: true,
|
|
36
|
-
entryFileNames: (chunkInfo) => `${chunkInfo.name}.${ext}`,
|
|
37
|
-
format,
|
|
38
|
-
sourcemap: true
|
|
39
|
-
});
|
|
66
|
+
await (await rollup(options)).write(outputOptions);
|
|
40
67
|
}
|
|
68
|
+
return errors.length + warnings.length;
|
|
41
69
|
};
|
|
42
70
|
const getInputs = async (subDir) => {
|
|
43
71
|
return (await readdir(subDir ? `src/${subDir}` : "src", { recursive: false })).filter((file) => (file.endsWith(".ts") || file.endsWith(".tsx")) && !file.endsWith("d.ts") && !file.endsWith("spec.ts")).map((file) => subDir ? `${subDir}/${file}` : file);
|
|
@@ -68,10 +96,9 @@ const buildIt = async (pkg) => {
|
|
|
68
96
|
const pkgType = pkg.type ?? "commonjs";
|
|
69
97
|
const esmExt = pkgType === "module" ? "js" : "mjs";
|
|
70
98
|
const cjsExt = pkgType === "commonjs" ? "js" : "cjs";
|
|
71
|
-
await Promise.all(
|
|
99
|
+
const rollupResult = await Promise.all(
|
|
72
100
|
inputDirs.map(async (inputDir) => {
|
|
73
|
-
await rollItUp("esm", esmExt, inputDir);
|
|
74
|
-
await rollItUp("cjs", cjsExt, inputDir);
|
|
101
|
+
return await rollItUp("esm", esmExt, inputDir) + await rollItUp("cjs", cjsExt, inputDir);
|
|
75
102
|
})
|
|
76
103
|
);
|
|
77
104
|
const distTypeFiles = await getDistTypeFiles();
|
|
@@ -86,7 +113,7 @@ const buildIt = async (pkg) => {
|
|
|
86
113
|
await copyFile(file, file.replace("d.ts.map", "d.mts.map"));
|
|
87
114
|
})
|
|
88
115
|
);
|
|
89
|
-
return 0;
|
|
116
|
+
return rollupResult.reduce((prev, item) => prev + item, 0);
|
|
90
117
|
};
|
|
91
118
|
const packageCompile = async ({ publint = true, verbose } = { verbose: false }) => {
|
|
92
119
|
const pkgName = process.env.npm_package_name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/package/compile.ts"],"sourcesContent":["import commonjs from '@rollup/plugin-commonjs'\nimport typescript from '@rollup/plugin-typescript'\nimport chalk from 'chalk'\nimport { copyFile, readdir } from 'fs/promises'\nimport { rollup } from 'rollup'\nimport externalDeps from 'rollup-plugin-exclude-dependencies-from-bundle'\nimport nodeExternals from 'rollup-plugin-node-externals'\n\nimport { loadPackageConfig, PackageJsonEx } from '../../loadPackageConfig'\nimport { packagePublint } from './publint'\n\nexport interface CompilePackageParams {\n publint?: boolean\n verbose?: boolean\n}\n\nconst rollItUp = async (format: 'cjs' | 'esm', ext: string, subDir?: string) => {\n const input = await getInputs(subDir)\n
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/package/compile.ts"],"sourcesContent":["import commonjs from '@rollup/plugin-commonjs'\nimport typescript from '@rollup/plugin-typescript'\nimport chalk from 'chalk'\nimport { copyFile, readdir } from 'fs/promises'\nimport { OutputOptions, rollup, RollupLog, RollupOptions, watch } from 'rollup'\nimport externalDeps from 'rollup-plugin-exclude-dependencies-from-bundle'\nimport nodeExternals from 'rollup-plugin-node-externals'\n\nimport { loadPackageConfig, PackageJsonEx } from '../../loadPackageConfig'\nimport { packagePublint } from './publint'\n\nexport interface CompilePackageParams {\n publint?: boolean\n verbose?: boolean\n}\n\nconst rollItUp = async (format: 'cjs' | 'esm', ext: string, subDir?: string) => {\n const input = await getInputs(subDir)\n const tsPlugIn = typescript({\n baseUrl: 'src',\n declaration: !subDir,\n declarationMap: !subDir,\n emitDeclarationOnly: false,\n esModuleInterop: true,\n exclude: ['**/*.spec.*', 'dist', 'docs', 'node_modules', 'packages'],\n outDir: subDir ? `dist/${subDir}` : 'dist',\n rootDir: 'src',\n tsconfig: 'tsconfig.json',\n })\n\n const errors: RollupLog[] = []\n const warnings: RollupLog[] = []\n const infos: RollupLog[] = []\n const debugs: RollupLog[] = []\n\n const options: RollupOptions = {\n input: input.map((file) => `./src/${file}`),\n logLevel: 'warn',\n onLog: (level, log, defaultHandler) => {\n switch (level) {\n case 'warn': {\n warnings.push(log)\n console.warn(chalk.yellow(JSON.stringify(log, null, 2)))\n break\n }\n case 'info': {\n infos.push(log)\n console.info(chalk.white(JSON.stringify(log, null, 2)))\n break\n }\n case 'debug': {\n debugs.push(log)\n console.debug(chalk.gray(JSON.stringify(log, null, 2)))\n break\n }\n default: {\n errors.push(log)\n console.error(chalk.red(JSON.stringify(log, null, 2)))\n break\n }\n }\n console.log(`Log: ${level}: ${log.cause}`)\n return defaultHandler(level, log)\n },\n plugins: [commonjs(), externalDeps(), nodeExternals(), tsPlugIn],\n }\n\n const outputOptions: OutputOptions = {\n dir: subDir ? `dist/${subDir}` : 'dist',\n dynamicImportInCjs: true,\n entryFileNames: (chunkInfo) => `${chunkInfo.name}.${ext}`,\n format,\n sourcemap: true,\n }\n\n if (input.length) {\n await (await rollup(options)).write(outputOptions)\n }\n\n return errors.length + warnings.length\n}\n\nconst getInputs = async (subDir?: string) => {\n return (await readdir(subDir ? `src/${subDir}` : 'src', { recursive: false }))\n .filter((file) => (file.endsWith('.ts') || file.endsWith('.tsx')) && !file.endsWith('d.ts') && !file.endsWith('spec.ts'))\n .map((file) => (subDir ? `${subDir}/${file}` : file))\n}\n\nconst getInputDirs = async () => {\n return [\n undefined,\n ...(await readdir('src', { recursive: true, withFileTypes: true }))\n .filter((file) => file.isDirectory())\n .map((file) => {\n const pathParts = file.path.split('/')\n pathParts.shift()\n if (pathParts.length) {\n const root = pathParts.join('/')\n return `${root}/${file.name}`\n } else {\n return file.name\n }\n }),\n ]\n}\n\nconst getDistTypeFiles = async () => {\n return (await readdir('dist', { recursive: true })).filter((file) => file.endsWith('d.ts')).map((file) => `dist/${file}`)\n}\n\nconst getDistTypeMapFiles = async () => {\n return (await readdir('dist', { recursive: true })).filter((file) => file.endsWith('d.ts.map')).map((file) => `dist/${file}`)\n}\n\nconst buildIt = async (pkg: PackageJsonEx) => {\n const inputDirs = await getInputDirs()\n\n const pkgType = pkg.type ?? 'commonjs'\n\n const esmExt = pkgType === 'module' ? 'js' : 'mjs'\n const cjsExt = pkgType === 'commonjs' ? 'js' : 'cjs'\n\n const rollupResult = await Promise.all(\n inputDirs.map(async (inputDir) => {\n return await rollItUp('esm', esmExt, inputDir) + await rollItUp('cjs', cjsExt, inputDir)\n }),\n )\n\n //hybrid packages want two copies of the types\n const distTypeFiles = await getDistTypeFiles()\n await Promise.all(\n distTypeFiles.map(async (file) => {\n await copyFile(file, file.replace('d.ts', 'd.mts'))\n }),\n )\n\n const distTypeMapFiles = await getDistTypeMapFiles()\n await Promise.all(\n distTypeMapFiles.map(async (file) => {\n await copyFile(file, file.replace('d.ts.map', 'd.mts.map'))\n }),\n )\n\n return rollupResult.reduce((prev, item) => prev + item, 0)\n}\n\nexport const packageCompile = async ({ publint = true, verbose }: CompilePackageParams = { verbose: false }) => {\n const pkgName = process.env.npm_package_name\n if (verbose) {\n console.log(chalk.green(`Compiling ${pkgName} Start`))\n }\n const result = (await buildIt(await loadPackageConfig())) + (publint ? await packagePublint() : 0)\n if (result) {\n const input = await getInputs()\n console.log(`Inputs: ${JSON.stringify(input, null, 2)}`)\n console.error(chalk.red(`Compiling ${pkgName} Failed [${result}]`))\n } else if (verbose) {\n console.log(chalk.green(`Compiling ${pkgName} Done`))\n }\n return result\n}\n"],"mappings":"AAAA,OAAO,cAAc;AACrB,OAAO,gBAAgB;AACvB,OAAO,WAAW;AAClB,SAAS,UAAU,eAAe;AAClC,SAAwB,cAA+C;AACvE,OAAO,kBAAkB;AACzB,OAAO,mBAAmB;AAE1B,SAAS,yBAAwC;AACjD,SAAS,sBAAsB;AAO/B,MAAM,WAAW,OAAO,QAAuB,KAAa,WAAoB;AAC9E,QAAM,QAAQ,MAAM,UAAU,MAAM;AACpC,QAAM,WAAW,WAAW;AAAA,IAC1B,SAAS;AAAA,IACT,aAAa,CAAC;AAAA,IACd,gBAAgB,CAAC;AAAA,IACjB,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,IACjB,SAAS,CAAC,eAAe,QAAQ,QAAQ,gBAAgB,UAAU;AAAA,IACnE,QAAQ,SAAS,QAAQ,MAAM,KAAK;AAAA,IACpC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AG,CAAC;AAAA,EACpE,WAAW,SAAS;AAClB,YAAQ,IAAI,MAAM,MAAM,aAAa,OAAO,OAAO,CAAC;AAAA,EACtD;AACA,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@types/yargs": "^17.0.24",
|
|
66
66
|
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
67
67
|
"@typescript-eslint/parser": "^6.7.0",
|
|
68
|
-
"@xylabs/tsconfig": "~3.0.
|
|
68
|
+
"@xylabs/tsconfig": "~3.0.4",
|
|
69
69
|
"chalk": "^4.1.2",
|
|
70
70
|
"cpy": "^8.1.2",
|
|
71
71
|
"depcheck": "^1.4.6",
|
|
@@ -108,8 +108,8 @@
|
|
|
108
108
|
"@types/license-checker": "^25.0.4",
|
|
109
109
|
"@types/lodash": "^4.14.198",
|
|
110
110
|
"@types/parse-git-config": "^3.0.1",
|
|
111
|
-
"@xylabs/eslint-config": "^3.0.
|
|
112
|
-
"@xylabs/tsconfig": "^3.0.
|
|
111
|
+
"@xylabs/eslint-config": "^3.0.4",
|
|
112
|
+
"@xylabs/tsconfig": "^3.0.4",
|
|
113
113
|
"publint": "^0.2.2",
|
|
114
114
|
"tsup": "^7.2.0",
|
|
115
115
|
"typescript": "^5.2.2"
|
|
@@ -167,5 +167,5 @@
|
|
|
167
167
|
"package-clean": "echo Not cleaning..."
|
|
168
168
|
},
|
|
169
169
|
"sideEffects": false,
|
|
170
|
-
"version": "3.0.
|
|
170
|
+
"version": "3.0.4"
|
|
171
171
|
}
|
|
@@ -2,7 +2,7 @@ import commonjs from '@rollup/plugin-commonjs'
|
|
|
2
2
|
import typescript from '@rollup/plugin-typescript'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
4
|
import { copyFile, readdir } from 'fs/promises'
|
|
5
|
-
import { rollup } from 'rollup'
|
|
5
|
+
import { OutputOptions, rollup, RollupLog, RollupOptions, watch } from 'rollup'
|
|
6
6
|
import externalDeps from 'rollup-plugin-exclude-dependencies-from-bundle'
|
|
7
7
|
import nodeExternals from 'rollup-plugin-node-externals'
|
|
8
8
|
|
|
@@ -16,37 +16,68 @@ export interface CompilePackageParams {
|
|
|
16
16
|
|
|
17
17
|
const rollItUp = async (format: 'cjs' | 'esm', ext: string, subDir?: string) => {
|
|
18
18
|
const input = await getInputs(subDir)
|
|
19
|
+
const tsPlugIn = typescript({
|
|
20
|
+
baseUrl: 'src',
|
|
21
|
+
declaration: !subDir,
|
|
22
|
+
declarationMap: !subDir,
|
|
23
|
+
emitDeclarationOnly: false,
|
|
24
|
+
esModuleInterop: true,
|
|
25
|
+
exclude: ['**/*.spec.*', 'dist', 'docs', 'node_modules', 'packages'],
|
|
26
|
+
outDir: subDir ? `dist/${subDir}` : 'dist',
|
|
27
|
+
rootDir: 'src',
|
|
28
|
+
tsconfig: 'tsconfig.json',
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const errors: RollupLog[] = []
|
|
32
|
+
const warnings: RollupLog[] = []
|
|
33
|
+
const infos: RollupLog[] = []
|
|
34
|
+
const debugs: RollupLog[] = []
|
|
35
|
+
|
|
36
|
+
const options: RollupOptions = {
|
|
37
|
+
input: input.map((file) => `./src/${file}`),
|
|
38
|
+
logLevel: 'warn',
|
|
39
|
+
onLog: (level, log, defaultHandler) => {
|
|
40
|
+
switch (level) {
|
|
41
|
+
case 'warn': {
|
|
42
|
+
warnings.push(log)
|
|
43
|
+
console.warn(chalk.yellow(JSON.stringify(log, null, 2)))
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
case 'info': {
|
|
47
|
+
infos.push(log)
|
|
48
|
+
console.info(chalk.white(JSON.stringify(log, null, 2)))
|
|
49
|
+
break
|
|
50
|
+
}
|
|
51
|
+
case 'debug': {
|
|
52
|
+
debugs.push(log)
|
|
53
|
+
console.debug(chalk.gray(JSON.stringify(log, null, 2)))
|
|
54
|
+
break
|
|
55
|
+
}
|
|
56
|
+
default: {
|
|
57
|
+
errors.push(log)
|
|
58
|
+
console.error(chalk.red(JSON.stringify(log, null, 2)))
|
|
59
|
+
break
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
console.log(`Log: ${level}: ${log.cause}`)
|
|
63
|
+
return defaultHandler(level, log)
|
|
64
|
+
},
|
|
65
|
+
plugins: [commonjs(), externalDeps(), nodeExternals(), tsPlugIn],
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const outputOptions: OutputOptions = {
|
|
69
|
+
dir: subDir ? `dist/${subDir}` : 'dist',
|
|
70
|
+
dynamicImportInCjs: true,
|
|
71
|
+
entryFileNames: (chunkInfo) => `${chunkInfo.name}.${ext}`,
|
|
72
|
+
format,
|
|
73
|
+
sourcemap: true,
|
|
74
|
+
}
|
|
75
|
+
|
|
19
76
|
if (input.length) {
|
|
20
|
-
await (
|
|
21
|
-
await rollup({
|
|
22
|
-
input: input.map((file) => `./src/${file}`),
|
|
23
|
-
logLevel: 'warn',
|
|
24
|
-
perf: true,
|
|
25
|
-
plugins: [
|
|
26
|
-
commonjs(),
|
|
27
|
-
externalDeps(),
|
|
28
|
-
nodeExternals(),
|
|
29
|
-
typescript({
|
|
30
|
-
baseUrl: './src',
|
|
31
|
-
declaration: !subDir,
|
|
32
|
-
declarationMap: !subDir,
|
|
33
|
-
emitDeclarationOnly: false,
|
|
34
|
-
esModuleInterop: true,
|
|
35
|
-
exclude: ['**/*.spec.*', 'dist', 'docs'],
|
|
36
|
-
outDir: subDir ? `dist/${subDir}` : 'dist',
|
|
37
|
-
rootDir: 'src',
|
|
38
|
-
tsconfig: 'tsconfig.json',
|
|
39
|
-
}),
|
|
40
|
-
],
|
|
41
|
-
})
|
|
42
|
-
).write({
|
|
43
|
-
dir: subDir ? `dist/${subDir}` : 'dist',
|
|
44
|
-
dynamicImportInCjs: true,
|
|
45
|
-
entryFileNames: (chunkInfo) => `${chunkInfo.name}.${ext}`,
|
|
46
|
-
format,
|
|
47
|
-
sourcemap: true,
|
|
48
|
-
})
|
|
77
|
+
await (await rollup(options)).write(outputOptions)
|
|
49
78
|
}
|
|
79
|
+
|
|
80
|
+
return errors.length + warnings.length
|
|
50
81
|
}
|
|
51
82
|
|
|
52
83
|
const getInputs = async (subDir?: string) => {
|
|
@@ -89,10 +120,9 @@ const buildIt = async (pkg: PackageJsonEx) => {
|
|
|
89
120
|
const esmExt = pkgType === 'module' ? 'js' : 'mjs'
|
|
90
121
|
const cjsExt = pkgType === 'commonjs' ? 'js' : 'cjs'
|
|
91
122
|
|
|
92
|
-
await Promise.all(
|
|
123
|
+
const rollupResult = await Promise.all(
|
|
93
124
|
inputDirs.map(async (inputDir) => {
|
|
94
|
-
await rollItUp('esm', esmExt, inputDir)
|
|
95
|
-
await rollItUp('cjs', cjsExt, inputDir)
|
|
125
|
+
return await rollItUp('esm', esmExt, inputDir) + await rollItUp('cjs', cjsExt, inputDir)
|
|
96
126
|
}),
|
|
97
127
|
)
|
|
98
128
|
|
|
@@ -111,7 +141,7 @@ const buildIt = async (pkg: PackageJsonEx) => {
|
|
|
111
141
|
}),
|
|
112
142
|
)
|
|
113
143
|
|
|
114
|
-
return 0
|
|
144
|
+
return rollupResult.reduce((prev, item) => prev + item, 0)
|
|
115
145
|
}
|
|
116
146
|
|
|
117
147
|
export const packageCompile = async ({ publint = true, verbose }: CompilePackageParams = { verbose: false }) => {
|