@sse-ui/builder 1.0.3 → 1.2.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.
- package/dist/acorn-RZKYEOCN.js +3130 -0
- package/dist/angular-65ZVA2AO.js +3070 -0
- package/dist/babel-6NAC7UZ3.js +7296 -0
- package/dist/babel-RJOLF3H5.js +12 -0
- package/dist/babel-config.js +14 -12
- package/dist/{chunk-5S2N5WDQ.js → chunk-B6FMAT44.js} +269 -52
- package/dist/{babel-VTL3CZAT.js → chunk-MBPIJFGX.js} +21 -18
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/cli.js +688 -439
- package/dist/config.d.ts +49 -30
- package/dist/config.js +2 -0
- package/dist/estree-SLPC3MKU.js +4612 -0
- package/dist/flow-JKSA2WQA.js +27546 -0
- package/dist/glimmer-KH4FHVWK.js +2894 -0
- package/dist/graphql-X7RDVKKC.js +1266 -0
- package/dist/html-A2DZMMEZ.js +2933 -0
- package/dist/markdown-35RS3VXW.js +3553 -0
- package/dist/meriyah-UIMGFPH2.js +2684 -0
- package/dist/postcss-CITECRUH.js +5080 -0
- package/dist/typescript-6QWCIZ3Q.js +20526 -0
- package/dist/typescript-CFZSZQGQ.js +13203 -0
- package/dist/yaml-RAY3ED75.js +4224 -0
- package/package.json +21 -6
- package/dist/typescript-CS6YZCMJ.js +0 -217
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
getVersionEnvVariables
|
|
4
|
+
} from "./chunk-MBPIJFGX.js";
|
|
5
|
+
import {
|
|
6
|
+
addLicense,
|
|
5
7
|
getOutExtension,
|
|
6
8
|
mapConcurrently,
|
|
7
|
-
validatePkgJson
|
|
8
|
-
|
|
9
|
+
validatePkgJson,
|
|
10
|
+
writePackageJson
|
|
11
|
+
} from "./chunk-B6FMAT44.js";
|
|
12
|
+
import "./chunk-MLKGABMK.js";
|
|
9
13
|
|
|
10
14
|
// src/cli.ts
|
|
15
|
+
import chalk2 from "chalk";
|
|
11
16
|
import { Command as Command11 } from "commander";
|
|
12
17
|
|
|
13
18
|
// src/core/build.ts
|
|
@@ -19,6 +24,8 @@ import * as path from "path";
|
|
|
19
24
|
import { sep as posixSep } from "path/posix";
|
|
20
25
|
import * as semver from "semver";
|
|
21
26
|
import { Command } from "commander";
|
|
27
|
+
import { build as esbuild } from "esbuild";
|
|
28
|
+
import chalk from "chalk";
|
|
22
29
|
|
|
23
30
|
// src/utils/loadConfig.ts
|
|
24
31
|
import { loadConfig as loadC12Config } from "c12";
|
|
@@ -29,7 +36,7 @@ async function loadConfig() {
|
|
|
29
36
|
rcFile: false,
|
|
30
37
|
globalRc: false
|
|
31
38
|
});
|
|
32
|
-
if (configFile) {
|
|
39
|
+
if (configFile && (config?.verbose || process.env.SSE_BUILD_VERBOSE === "true")) {
|
|
33
40
|
console.log(`\u{1F4DD} Loaded config from ${configFile}`);
|
|
34
41
|
}
|
|
35
42
|
return config || {};
|
|
@@ -40,95 +47,22 @@ async function loadConfig() {
|
|
|
40
47
|
}
|
|
41
48
|
}
|
|
42
49
|
|
|
43
|
-
// src/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
outputDir,
|
|
50
|
-
isFlat,
|
|
51
|
-
packageType
|
|
52
|
-
}) {
|
|
53
|
-
const outExtension = getOutExtension(bundle, { isFlat, packageType });
|
|
54
|
-
const file = path.join(outputDir, `index${outExtension}`);
|
|
55
|
-
if (!await fs.stat(file).then(
|
|
56
|
-
(stats) => stats.isFile(),
|
|
57
|
-
() => false
|
|
58
|
-
)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const content = await fs.readFile(file, { encoding: "utf8" });
|
|
62
|
-
await fs.writeFile(
|
|
63
|
-
file,
|
|
64
|
-
`/**
|
|
65
|
-
* ${name} v${version}
|
|
66
|
-
*
|
|
67
|
-
* @license ${license}
|
|
68
|
-
* This source code is licensed under the ${license} license found in the
|
|
69
|
-
* LICENSE file in the root directory of this source tree.
|
|
70
|
-
*/
|
|
71
|
-
${content}`,
|
|
72
|
-
{ encoding: "utf8" }
|
|
73
|
-
);
|
|
74
|
-
console.log(`License added to ${file}`);
|
|
50
|
+
// src/utils/package-manager.ts
|
|
51
|
+
function getPackageManager() {
|
|
52
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
53
|
+
if (userAgent.includes("pnpm")) return "pnpm";
|
|
54
|
+
if (userAgent.includes("yarn")) return "yarn";
|
|
55
|
+
return "npm";
|
|
75
56
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
addTypes = false,
|
|
82
|
-
isFlat = false,
|
|
83
|
-
packageType
|
|
84
|
-
}) {
|
|
85
|
-
delete packageJson.scripts;
|
|
86
|
-
delete packageJson.publishConfig?.directory;
|
|
87
|
-
delete packageJson.devDependencies;
|
|
88
|
-
delete packageJson.imports;
|
|
89
|
-
const resolvedPackageType = packageType || packageJson.type || "commonjs";
|
|
90
|
-
packageJson.type = resolvedPackageType;
|
|
91
|
-
const originalExports = packageJson.exports;
|
|
92
|
-
delete packageJson.exports;
|
|
93
|
-
const originalBin = packageJson.bin;
|
|
94
|
-
delete packageJson.bin;
|
|
95
|
-
const {
|
|
96
|
-
exports: packageExports,
|
|
97
|
-
main: main2,
|
|
98
|
-
types
|
|
99
|
-
} = await createPackageExports({
|
|
100
|
-
exports: originalExports,
|
|
101
|
-
bundles,
|
|
102
|
-
outputDir,
|
|
103
|
-
cwd,
|
|
104
|
-
addTypes,
|
|
105
|
-
isFlat,
|
|
106
|
-
packageType: resolvedPackageType
|
|
107
|
-
});
|
|
108
|
-
packageJson.exports = packageExports;
|
|
109
|
-
if (main2) {
|
|
110
|
-
packageJson.main = main2;
|
|
111
|
-
}
|
|
112
|
-
if (types) {
|
|
113
|
-
packageJson.types = types;
|
|
114
|
-
}
|
|
115
|
-
const bin = await createPackageBin({
|
|
116
|
-
bin: originalBin,
|
|
117
|
-
bundles,
|
|
118
|
-
cwd,
|
|
119
|
-
isFlat,
|
|
120
|
-
packageType: resolvedPackageType
|
|
121
|
-
});
|
|
122
|
-
if (bin) {
|
|
123
|
-
packageJson.bin = bin;
|
|
124
|
-
}
|
|
125
|
-
await fs.writeFile(
|
|
126
|
-
path.join(outputDir, "package.json"),
|
|
127
|
-
JSON.stringify(packageJson, null, 2),
|
|
128
|
-
"utf-8"
|
|
129
|
-
);
|
|
57
|
+
function getPmExec() {
|
|
58
|
+
const pm = getPackageManager();
|
|
59
|
+
if (pm === "pnpm") return ["pnpm", "exec"];
|
|
60
|
+
if (pm === "yarn") return ["yarn"];
|
|
61
|
+
return ["npx"];
|
|
130
62
|
}
|
|
131
|
-
|
|
63
|
+
|
|
64
|
+
// src/core/build.ts
|
|
65
|
+
var buildCommand = new Command("build").description(chalk.cyan("Builds the package for publishing.")).option("--bundle <bundles...>", "Bundles to output", ["esm", "cjs"]).option("--entry <entry>", "Entry point for esbuild (e.g., src/index.ts)").option(
|
|
132
66
|
"--hasLargeFiles",
|
|
133
67
|
"Set to `true` if you know you are transpiling large files.",
|
|
134
68
|
false
|
|
@@ -158,67 +92,76 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
158
92
|
[]
|
|
159
93
|
).option("--enableReactCompiler", "Whether to use the React compiler.", false).option(
|
|
160
94
|
"--tsgo",
|
|
161
|
-
|
|
95
|
+
"Uses tsgo cli instead of tsc for type generation.",
|
|
162
96
|
process.env.SSE_USE_TSGO === "1" || process.env.SSE_USE_TSGO === "true"
|
|
163
97
|
).option(
|
|
164
98
|
"--flat",
|
|
165
99
|
"Builds the package in a flat structure without subdirectories for each module type.",
|
|
166
100
|
process.env.SSE_BUILD_FLAT === "1"
|
|
167
|
-
).option(
|
|
101
|
+
).option(
|
|
102
|
+
"--exportExtensions <exts...>",
|
|
103
|
+
"Available extensions for generating exports wildcards.",
|
|
104
|
+
[".js", ".mjs", ".cjs"]
|
|
105
|
+
).action(async (cliOptions) => {
|
|
168
106
|
const fileConfig = await loadConfig();
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
const {
|
|
186
|
-
bundle: bundles,
|
|
187
|
-
hasLargeFiles,
|
|
188
|
-
skipBundlePackageJson,
|
|
189
|
-
verbose = false,
|
|
190
|
-
ignore: extraIgnores,
|
|
191
|
-
buildTypes,
|
|
192
|
-
skipTsc,
|
|
193
|
-
skipBabelRuntimeCheck = false,
|
|
194
|
-
skipPackageJson = false,
|
|
195
|
-
enableReactCompiler = false,
|
|
196
|
-
tsgo: useTsgo = false
|
|
197
|
-
} = options;
|
|
107
|
+
const isVerbose = cliOptions.verbose || fileConfig.verbose || process.env.SSE_BUILD_VERBOSE === "true";
|
|
108
|
+
if (isVerbose) process.env.SSE_BUILD_VERBOSE = "true";
|
|
109
|
+
const isEsbuild = !!fileConfig.esbuild || !!cliOptions.entry;
|
|
110
|
+
const builder = isEsbuild ? "esbuild" : "babel";
|
|
111
|
+
const bundles = cliOptions.bundle || fileConfig.bundle || ["esm", "cjs"];
|
|
112
|
+
const isFlat = cliOptions.flat ?? fileConfig.flat ?? false;
|
|
113
|
+
const buildTypes = cliOptions.buildTypes ?? fileConfig.buildTypes ?? true;
|
|
114
|
+
const skipTsc = cliOptions.skipTsc ?? fileConfig.skipTsc ?? false;
|
|
115
|
+
const skipBundlePackageJson = cliOptions.skipBundlePackageJson ?? fileConfig.skipBundlePackageJson ?? false;
|
|
116
|
+
const skipBabelRuntimeCheck = cliOptions.skipBabelRuntimeCheck ?? false;
|
|
117
|
+
const skipPackageJson = cliOptions.skipPackageJson ?? false;
|
|
118
|
+
const enableReactCompiler = cliOptions.enableReactCompiler ?? fileConfig.babel?.enableReactCompiler ?? false;
|
|
119
|
+
const useTsgo = cliOptions.tsgo ?? fileConfig.tsgo ?? false;
|
|
120
|
+
const exportExtensions = cliOptions.exportExtensions ?? fileConfig.exportExtensions ?? [".js", ".mjs", ".cjs"];
|
|
121
|
+
const copyGlobs = [...fileConfig.copy || [], ...cliOptions.copy || []];
|
|
198
122
|
const cwd = process.cwd();
|
|
199
123
|
const pkgJsonPath = path.join(cwd, "package.json");
|
|
200
124
|
const packageJson = JSON.parse(
|
|
201
125
|
await fs.readFile(pkgJsonPath, { encoding: "utf8" })
|
|
202
126
|
);
|
|
203
127
|
validatePkgJson(packageJson, {
|
|
204
|
-
skipMainCheck:
|
|
128
|
+
skipMainCheck: cliOptions.skipMainCheck,
|
|
205
129
|
enableReactCompiler
|
|
206
130
|
});
|
|
207
131
|
const buildDirBase = packageJson.publishConfig?.directory;
|
|
208
132
|
const buildDir = path.join(cwd, buildDirBase);
|
|
209
133
|
const packageType = packageJson.type === "module" ? "module" : "commonjs";
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
console.log("Building package in flat structure.");
|
|
134
|
+
if (isVerbose) {
|
|
135
|
+
console.log(`Selected output directory: "${buildDirBase}"`);
|
|
136
|
+
if (isFlat) console.log("Building package in flat structure.");
|
|
213
137
|
}
|
|
214
138
|
await fs.rm(buildDir, { recursive: true, force: true });
|
|
139
|
+
const pm = getPackageManager();
|
|
215
140
|
let babelRuntimeVersion = packageJson.dependencies?.["@babel/runtime"];
|
|
216
141
|
if (babelRuntimeVersion === "catalog:") {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
142
|
+
if (pm === "pnpm") {
|
|
143
|
+
try {
|
|
144
|
+
const { stdout: configStdout } = await $`pnpm config list --json`;
|
|
145
|
+
const pnpmWorkspaceConfig = JSON.parse(configStdout);
|
|
146
|
+
babelRuntimeVersion = pnpmWorkspaceConfig.catalog["@babel/runtime"];
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (isVerbose)
|
|
149
|
+
console.warn(
|
|
150
|
+
`
|
|
151
|
+
\u26A0\uFE0F Failed to resolve 'catalog:' using pnpm. Falling back to default.`
|
|
152
|
+
);
|
|
153
|
+
babelRuntimeVersion = "^7.25.0";
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
if (isVerbose)
|
|
157
|
+
console.warn(
|
|
158
|
+
`
|
|
159
|
+
\u26A0\uFE0F 'catalog:' dependency found but package manager is ${pm}. Falling back to default babel runtime version.`
|
|
160
|
+
);
|
|
161
|
+
babelRuntimeVersion = "^7.25.0";
|
|
162
|
+
}
|
|
220
163
|
}
|
|
221
|
-
if (!babelRuntimeVersion && !skipBabelRuntimeCheck) {
|
|
164
|
+
if (builder === "babel" && !babelRuntimeVersion && !skipBabelRuntimeCheck) {
|
|
222
165
|
throw new Error(
|
|
223
166
|
"package.json needs to have a dependency on `@babel/runtime` when building with `@babel/plugin-transform-runtime`."
|
|
224
167
|
);
|
|
@@ -229,101 +172,169 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
229
172
|
);
|
|
230
173
|
return;
|
|
231
174
|
}
|
|
232
|
-
const {
|
|
233
|
-
const relativeOutDirs = !options.flat ? {
|
|
234
|
-
cjs: ".",
|
|
235
|
-
esm: "esm"
|
|
236
|
-
} : {
|
|
237
|
-
cjs: ".",
|
|
238
|
-
esm: "."
|
|
239
|
-
};
|
|
175
|
+
const relativeOutDirs = !isFlat ? { cjs: ".", esm: "esm" } : { cjs: ".", esm: "." };
|
|
240
176
|
const sourceDir = path.join(cwd, "src");
|
|
241
177
|
const reactVersion = semver.minVersion(packageJson.peerDependencies?.react || "")?.version ?? "latest";
|
|
242
|
-
if (enableReactCompiler) {
|
|
178
|
+
if (enableReactCompiler && isVerbose) {
|
|
243
179
|
const mode = process.env.SSE_REACT_COMPILER_MODE ?? "opt-in";
|
|
244
180
|
console.log(
|
|
245
181
|
`[feature] Building with React compiler enabled. The compiler mode is "${mode}" right now.${mode === "opt-in" ? ' Use explicit "use memo" directives in your components to enable the React compiler for them.' : ""}`
|
|
246
182
|
);
|
|
247
183
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const outputDir = path.join(buildDir, relativeOutDir);
|
|
257
|
-
await fs.mkdir(outputDir, { recursive: true });
|
|
258
|
-
const promises = [];
|
|
259
|
-
promises.push(
|
|
260
|
-
babelBuild({
|
|
261
|
-
cwd,
|
|
262
|
-
sourceDir,
|
|
263
|
-
outDir: outputDir,
|
|
264
|
-
babelRuntimeVersion,
|
|
265
|
-
hasLargeFiles,
|
|
266
|
-
bundle,
|
|
267
|
-
verbose,
|
|
268
|
-
optimizeClsx: packageJson.dependencies?.clsx !== void 0 || packageJson.dependencies?.classnames !== void 0,
|
|
269
|
-
removePropTypes: packageJson.dependencies?.["prop-types"] !== void 0,
|
|
270
|
-
pkgVersion: packageJson.version,
|
|
271
|
-
ignores: extraIgnores,
|
|
272
|
-
outExtension,
|
|
273
|
-
reactCompiler: enableReactCompiler ? {
|
|
274
|
-
reactVersion: reactVersion || "latest"
|
|
275
|
-
} : void 0
|
|
276
|
-
})
|
|
184
|
+
if (builder === "esbuild") {
|
|
185
|
+
if (isVerbose)
|
|
186
|
+
console.log("\u{1F4E6} Bundling package into single files via esbuild...");
|
|
187
|
+
const esbuildConfig = fileConfig.esbuild || { entry: "src/index.ts" };
|
|
188
|
+
let rawEntryPoints = cliOptions.entry || esbuildConfig.entry;
|
|
189
|
+
if (!rawEntryPoints) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
"Esbuild requires an 'entry' point. Please define it in your config (esbuild.entry) or via --entry."
|
|
277
192
|
);
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
193
|
+
}
|
|
194
|
+
const entryPoints = typeof rawEntryPoints === "string" ? [rawEntryPoints] : rawEntryPoints;
|
|
195
|
+
await Promise.all(
|
|
196
|
+
bundles.map(async (bundle) => {
|
|
197
|
+
const outExtension = getOutExtension(bundle, {
|
|
198
|
+
isFlat: !!isFlat,
|
|
199
|
+
isType: false,
|
|
200
|
+
packageType
|
|
201
|
+
});
|
|
202
|
+
const relativeOutDir = relativeOutDirs[bundle];
|
|
203
|
+
const outputDir = path.join(buildDir, relativeOutDir);
|
|
204
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
205
|
+
await esbuild({
|
|
206
|
+
entryPoints,
|
|
207
|
+
bundle: true,
|
|
208
|
+
outdir: outputDir,
|
|
209
|
+
format: bundle === "esm" ? "esm" : "cjs",
|
|
210
|
+
target: esbuildConfig.target || ["es2020", "node14"],
|
|
211
|
+
minify: esbuildConfig.minify ?? false,
|
|
212
|
+
outExtension: { ".js": outExtension },
|
|
213
|
+
// Forces the correct extension output
|
|
214
|
+
external: [
|
|
215
|
+
...Object.keys(packageJson.dependencies || {}),
|
|
216
|
+
...Object.keys(packageJson.peerDependencies || {}),
|
|
217
|
+
...esbuildConfig.external || []
|
|
218
|
+
]
|
|
219
|
+
});
|
|
220
|
+
if (buildDir !== outputDir && !skipBundlePackageJson && !isFlat) {
|
|
221
|
+
await fs.writeFile(
|
|
281
222
|
path.join(outputDir, "package.json"),
|
|
282
223
|
JSON.stringify({
|
|
283
224
|
type: bundle === "esm" ? "module" : "commonjs",
|
|
284
225
|
sideEffects: packageJson.sideEffects ?? false
|
|
285
226
|
})
|
|
286
|
-
)
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
await addLicense({
|
|
230
|
+
bundle,
|
|
231
|
+
license: packageJson.license,
|
|
232
|
+
name: packageJson.name,
|
|
233
|
+
version: packageJson.version,
|
|
234
|
+
outputDir,
|
|
235
|
+
isFlat: !!isFlat,
|
|
236
|
+
packageType
|
|
237
|
+
});
|
|
238
|
+
})
|
|
239
|
+
);
|
|
240
|
+
} else {
|
|
241
|
+
if (isVerbose) console.log("\u{1F4E6} Transpiling package via Babel...");
|
|
242
|
+
const { build: babelBuild, cjsCopy } = await import("./babel-RJOLF3H5.js");
|
|
243
|
+
const hasLargeFiles = cliOptions.hasLargeFiles ?? fileConfig.babel?.hasLargeFiles ?? false;
|
|
244
|
+
const extraIgnores = [
|
|
245
|
+
...fileConfig.babel?.ignore || [],
|
|
246
|
+
...cliOptions.ignore || []
|
|
247
|
+
];
|
|
248
|
+
await Promise.all(
|
|
249
|
+
bundles.map(async (bundle) => {
|
|
250
|
+
const outExtension = getOutExtension(bundle, {
|
|
251
|
+
isFlat: !!isFlat,
|
|
252
|
+
isType: false,
|
|
253
|
+
packageType
|
|
254
|
+
});
|
|
255
|
+
const relativeOutDir = relativeOutDirs[bundle];
|
|
256
|
+
const outputDir = path.join(buildDir, relativeOutDir);
|
|
257
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
258
|
+
const promises = [];
|
|
259
|
+
promises.push(
|
|
260
|
+
babelBuild({
|
|
261
|
+
cwd,
|
|
262
|
+
sourceDir,
|
|
263
|
+
outDir: outputDir,
|
|
264
|
+
babelRuntimeVersion,
|
|
265
|
+
hasLargeFiles,
|
|
266
|
+
bundle,
|
|
267
|
+
verbose: isVerbose,
|
|
268
|
+
optimizeClsx: packageJson.dependencies?.clsx !== void 0 || packageJson.dependencies?.classnames !== void 0,
|
|
269
|
+
removePropTypes: packageJson.dependencies?.["prop-types"] !== void 0,
|
|
270
|
+
pkgVersion: packageJson.version,
|
|
271
|
+
ignores: extraIgnores,
|
|
272
|
+
outExtension,
|
|
273
|
+
reactCompiler: enableReactCompiler ? { reactVersion: reactVersion || "latest" } : void 0
|
|
274
|
+
})
|
|
287
275
|
);
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
isFlat
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
276
|
+
if (buildDir !== outputDir && !skipBundlePackageJson && !isFlat) {
|
|
277
|
+
promises.push(
|
|
278
|
+
fs.writeFile(
|
|
279
|
+
path.join(outputDir, "package.json"),
|
|
280
|
+
JSON.stringify({
|
|
281
|
+
type: bundle === "esm" ? "module" : "commonjs",
|
|
282
|
+
sideEffects: packageJson.sideEffects ?? false
|
|
283
|
+
})
|
|
284
|
+
)
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
if (!isFlat) {
|
|
288
|
+
promises.push(cjsCopy({ from: sourceDir, to: outputDir }));
|
|
289
|
+
}
|
|
290
|
+
await Promise.all(promises);
|
|
291
|
+
await addLicense({
|
|
292
|
+
bundle,
|
|
293
|
+
license: packageJson.license,
|
|
294
|
+
name: packageJson.name,
|
|
295
|
+
version: packageJson.version,
|
|
296
|
+
outputDir,
|
|
297
|
+
isFlat: !!isFlat,
|
|
298
|
+
packageType
|
|
299
|
+
});
|
|
300
|
+
})
|
|
301
|
+
);
|
|
302
|
+
if (isFlat) {
|
|
303
|
+
await cjsCopy({ from: sourceDir, to: buildDir });
|
|
304
|
+
}
|
|
306
305
|
}
|
|
307
|
-
if (buildTypes) {
|
|
308
|
-
|
|
306
|
+
if (buildTypes === true) {
|
|
307
|
+
if (isVerbose) console.log("\u{1F4DD} Generating TypeScript declarations...");
|
|
308
|
+
const tsMod = await import("./typescript-6QWCIZ3Q.js");
|
|
309
309
|
const bundleMap = bundles.map((type) => ({
|
|
310
310
|
type,
|
|
311
311
|
dir: relativeOutDirs[type]
|
|
312
312
|
}));
|
|
313
|
+
let esbuildEntryPoints;
|
|
314
|
+
if (builder === "esbuild") {
|
|
315
|
+
const esbuildConfig = fileConfig.esbuild || { entry: "src/index.ts" };
|
|
316
|
+
const rawEntryPoints = cliOptions.entry || esbuildConfig.entry;
|
|
317
|
+
esbuildEntryPoints = typeof rawEntryPoints === "string" ? [rawEntryPoints] : rawEntryPoints;
|
|
318
|
+
}
|
|
313
319
|
await tsMod.createTypes({
|
|
314
320
|
bundles: bundleMap,
|
|
315
321
|
srcDir: sourceDir,
|
|
316
322
|
cwd,
|
|
317
323
|
skipTsc,
|
|
318
|
-
isFlat: !!
|
|
324
|
+
isFlat: !!isFlat,
|
|
319
325
|
buildDir,
|
|
320
326
|
useTsgo,
|
|
321
327
|
packageType,
|
|
322
|
-
verbose:
|
|
328
|
+
verbose: isVerbose,
|
|
329
|
+
builder,
|
|
330
|
+
entryPoints: esbuildEntryPoints
|
|
323
331
|
});
|
|
324
332
|
}
|
|
325
333
|
if (skipPackageJson) {
|
|
326
|
-
|
|
334
|
+
if (isVerbose)
|
|
335
|
+
console.log(
|
|
336
|
+
"Skipping package.json generation in the output directory."
|
|
337
|
+
);
|
|
327
338
|
return;
|
|
328
339
|
}
|
|
329
340
|
await writePackageJson({
|
|
@@ -335,14 +346,15 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
335
346
|
})),
|
|
336
347
|
outputDir: buildDir,
|
|
337
348
|
addTypes: buildTypes,
|
|
338
|
-
isFlat: !!
|
|
339
|
-
packageType
|
|
349
|
+
isFlat: !!isFlat,
|
|
350
|
+
packageType,
|
|
351
|
+
exportExtensions
|
|
340
352
|
});
|
|
341
353
|
await copyHandler({
|
|
342
354
|
cwd,
|
|
343
|
-
globs:
|
|
355
|
+
globs: copyGlobs,
|
|
344
356
|
buildDir,
|
|
345
|
-
verbose:
|
|
357
|
+
verbose: isVerbose
|
|
346
358
|
});
|
|
347
359
|
});
|
|
348
360
|
async function copyHandler({
|
|
@@ -366,13 +378,10 @@ async function copyHandler({
|
|
|
366
378
|
await Promise.all(
|
|
367
379
|
localOrRootFiles.map(async (filesToCopy) => {
|
|
368
380
|
for (const file of filesToCopy) {
|
|
369
|
-
if (
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
() => false
|
|
374
|
-
)
|
|
375
|
-
) {
|
|
381
|
+
if (await fs.stat(file).then(
|
|
382
|
+
() => true,
|
|
383
|
+
() => false
|
|
384
|
+
)) {
|
|
376
385
|
defaultFiles.push(file);
|
|
377
386
|
break;
|
|
378
387
|
}
|
|
@@ -437,7 +446,7 @@ async function copyHandler({
|
|
|
437
446
|
},
|
|
438
447
|
20
|
|
439
448
|
);
|
|
440
|
-
console.log(`\u{1F4CB} Copied ${defaultFiles.length} files.`);
|
|
449
|
+
if (verbose) console.log(`\u{1F4CB} Copied ${defaultFiles.length} files.`);
|
|
441
450
|
}
|
|
442
451
|
async function recursiveCopy({
|
|
443
452
|
source,
|
|
@@ -466,12 +475,6 @@ import * as fs2 from "fs/promises";
|
|
|
466
475
|
import * as path2 from "path";
|
|
467
476
|
import { Command as Command2 } from "commander";
|
|
468
477
|
import { $ as $2 } from "execa";
|
|
469
|
-
function getPackageManager() {
|
|
470
|
-
const userAgent = process.env.npm_config_user_agent || "";
|
|
471
|
-
if (userAgent.includes("pnpm")) return "pnpm";
|
|
472
|
-
if (userAgent.includes("yarn")) return "yarn";
|
|
473
|
-
return "npm";
|
|
474
|
-
}
|
|
475
478
|
var publishCommand = new Command2("publish").description(
|
|
476
479
|
"Automatically publishes the built package from the publishConfig.directory"
|
|
477
480
|
).option("--tag <tag>", "Registers the published package with the given tag").option(
|
|
@@ -484,6 +487,7 @@ var publishCommand = new Command2("publish").description(
|
|
|
484
487
|
"--pm <manager>",
|
|
485
488
|
"Force a specific package manager (npm, yarn, pnpm)"
|
|
486
489
|
).action(async (options) => {
|
|
490
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
487
491
|
const cwd = process.cwd();
|
|
488
492
|
const pkgJsonPath = path2.join(cwd, "package.json");
|
|
489
493
|
try {
|
|
@@ -508,9 +512,11 @@ var publishCommand = new Command2("publish").description(
|
|
|
508
512
|
);
|
|
509
513
|
}
|
|
510
514
|
const pm = options.pm || getPackageManager();
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
515
|
+
if (isVerbose) {
|
|
516
|
+
console.log(
|
|
517
|
+
`\u{1F680} Publishing via ${pm.toUpperCase()} from directory: ${publishDirBase}`
|
|
518
|
+
);
|
|
519
|
+
}
|
|
514
520
|
const args = ["publish"];
|
|
515
521
|
if (options.tag) args.push("--tag", options.tag);
|
|
516
522
|
if (options.access) args.push("--access", options.access);
|
|
@@ -539,6 +545,7 @@ import { Command as Command3 } from "commander";
|
|
|
539
545
|
var cleanCommand = new Command3("clean").description(
|
|
540
546
|
"Removes the build directory specified in package.json to start fresh"
|
|
541
547
|
).action(async () => {
|
|
548
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
542
549
|
const cwd = process.cwd();
|
|
543
550
|
const pkgJsonPath = path3.join(cwd, "package.json");
|
|
544
551
|
try {
|
|
@@ -548,7 +555,8 @@ var cleanCommand = new Command3("clean").description(
|
|
|
548
555
|
const packageJson = JSON.parse(packageJsonContent);
|
|
549
556
|
const buildDirBase = packageJson.publishConfig?.directory || "build";
|
|
550
557
|
const buildDir = path3.join(cwd, buildDirBase);
|
|
551
|
-
|
|
558
|
+
if (isVerbose)
|
|
559
|
+
console.log(`\u{1F9F9} Cleaning build directory: ${buildDirBase}...`);
|
|
552
560
|
await fs3.rm(buildDir, { recursive: true, force: true });
|
|
553
561
|
console.log("\u2728 Cleaned successfully!");
|
|
554
562
|
} catch (error) {
|
|
@@ -566,7 +574,8 @@ import { $ as $3 } from "execa";
|
|
|
566
574
|
var typecheckCommand = new Command4("typecheck").description(
|
|
567
575
|
"Runs TypeScript validation across the project without emitting files"
|
|
568
576
|
).option("--watch", "Run typechecking in watch mode").action(async (options) => {
|
|
569
|
-
|
|
577
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
578
|
+
if (isVerbose) console.log("\u{1F50D} Running typecheck...");
|
|
570
579
|
try {
|
|
571
580
|
const args = ["tsc", "--noEmit"];
|
|
572
581
|
if (options.watch) {
|
|
@@ -592,6 +601,8 @@ import { $ as $4 } from "execa";
|
|
|
592
601
|
var packCommand = new Command5("pack").description(
|
|
593
602
|
"Creates a tarball (.tgz) of the built package to inspect before publishing"
|
|
594
603
|
).action(async () => {
|
|
604
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
605
|
+
const pm = getPackageManager();
|
|
595
606
|
const cwd = process.cwd();
|
|
596
607
|
const pkgJsonPath = path4.join(cwd, "package.json");
|
|
597
608
|
try {
|
|
@@ -604,11 +615,12 @@ var packCommand = new Command5("pack").description(
|
|
|
604
615
|
throw new Error(`No publish directory specified in package.json.`);
|
|
605
616
|
}
|
|
606
617
|
const publishDir = path4.join(cwd, publishDirBase);
|
|
607
|
-
|
|
618
|
+
if (isVerbose)
|
|
619
|
+
console.log(`\u{1F4E6} Packing package from directory: ${publishDirBase}...`);
|
|
608
620
|
await $4({
|
|
609
621
|
stdio: "inherit",
|
|
610
622
|
cwd: publishDir
|
|
611
|
-
})
|
|
623
|
+
})`${pm} pack`;
|
|
612
624
|
console.log(
|
|
613
625
|
"\u2705 Pack successful! You can inspect the generated .tgz file."
|
|
614
626
|
);
|
|
@@ -620,12 +632,19 @@ var packCommand = new Command5("pack").description(
|
|
|
620
632
|
});
|
|
621
633
|
|
|
622
634
|
// src/core/version.ts
|
|
635
|
+
import * as fs5 from "fs/promises";
|
|
636
|
+
import * as path5 from "path";
|
|
623
637
|
import { Command as Command6 } from "commander";
|
|
624
638
|
import { $ as $5 } from "execa";
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
639
|
+
import enquirer from "enquirer";
|
|
640
|
+
import * as semver2 from "semver";
|
|
641
|
+
var versionCommand = new Command6("version").description("Bumps the package version interactively or manually").argument(
|
|
642
|
+
"[type]",
|
|
643
|
+
"Version update type (patch, minor, major, or specific version like 1.2.3). If omitted, an interactive prompt will appear."
|
|
628
644
|
).option("--no-git-tag-version", "Do not create a git tag").action(async (type, options) => {
|
|
645
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
646
|
+
const pm = getPackageManager();
|
|
647
|
+
const cwd = process.cwd();
|
|
629
648
|
const validTypes = [
|
|
630
649
|
"patch",
|
|
631
650
|
"minor",
|
|
@@ -635,19 +654,64 @@ var versionCommand = new Command6("version").description("Bumps the package vers
|
|
|
635
654
|
"premajor",
|
|
636
655
|
"prerelease"
|
|
637
656
|
];
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
657
|
+
let selectedType = type;
|
|
658
|
+
if (!selectedType) {
|
|
659
|
+
let currentVersion = "0.0.0";
|
|
660
|
+
try {
|
|
661
|
+
const pkgJsonPath = path5.join(cwd, "package.json");
|
|
662
|
+
const pkgContent = await fs5.readFile(pkgJsonPath, "utf-8");
|
|
663
|
+
currentVersion = JSON.parse(pkgContent).version || "0.0.0";
|
|
664
|
+
} catch (err) {
|
|
665
|
+
if (isVerbose)
|
|
666
|
+
console.warn(
|
|
667
|
+
"\u26A0\uFE0F Could not read current version from package.json. Defaulting to 0.0.0"
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
const choices = validTypes.map((bump) => {
|
|
671
|
+
const nextVersion = semver2.inc(currentVersion, bump);
|
|
672
|
+
return {
|
|
673
|
+
name: bump,
|
|
674
|
+
message: `${bump.padEnd(10)} (v${nextVersion})`
|
|
675
|
+
};
|
|
676
|
+
});
|
|
677
|
+
const { bumpType } = await enquirer.prompt({
|
|
678
|
+
type: "select",
|
|
679
|
+
name: "bumpType",
|
|
680
|
+
message: `Current version: ${currentVersion}. Select version bump type:`,
|
|
681
|
+
choices: [...choices, { name: "custom", message: "custom..." }]
|
|
682
|
+
});
|
|
683
|
+
if (bumpType === "custom") {
|
|
684
|
+
const { customVersion } = await enquirer.prompt({
|
|
685
|
+
type: "input",
|
|
686
|
+
name: "customVersion",
|
|
687
|
+
message: "Enter custom version (e.g., 1.2.3):",
|
|
688
|
+
validate: (value) => {
|
|
689
|
+
if (semver2.valid(value)) {
|
|
690
|
+
return true;
|
|
691
|
+
}
|
|
692
|
+
return "Please enter a valid semver version (e.g., 1.2.3 or 1.2.3-beta.1)";
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
selectedType = customVersion;
|
|
696
|
+
} else {
|
|
697
|
+
selectedType = bumpType;
|
|
698
|
+
}
|
|
699
|
+
} else {
|
|
700
|
+
if (!validTypes.includes(selectedType) && !semver2.valid(selectedType)) {
|
|
701
|
+
console.error(
|
|
702
|
+
`\u274C Invalid version type: ${selectedType}. Use patch, minor, major, or a valid semver.`
|
|
703
|
+
);
|
|
704
|
+
process.exit(1);
|
|
705
|
+
}
|
|
643
706
|
}
|
|
644
|
-
|
|
707
|
+
if (isVerbose)
|
|
708
|
+
console.log(`\u{1F4C8} Bumping version (${selectedType}) via ${pm}...`);
|
|
645
709
|
try {
|
|
646
|
-
const args = ["version",
|
|
710
|
+
const args = ["version", selectedType];
|
|
647
711
|
if (!options.gitTagVersion) {
|
|
648
712
|
args.push("--no-git-tag-version");
|
|
649
713
|
}
|
|
650
|
-
await $5({ stdio: "inherit" })
|
|
714
|
+
await $5({ stdio: isVerbose ? "inherit" : "pipe" })`${pm} ${args}`;
|
|
651
715
|
console.log("\u2705 Version bumped successfully!");
|
|
652
716
|
} catch (error) {
|
|
653
717
|
console.error("\u274C Failed to bump version.");
|
|
@@ -656,28 +720,29 @@ var versionCommand = new Command6("version").description("Bumps the package vers
|
|
|
656
720
|
});
|
|
657
721
|
|
|
658
722
|
// src/core/info.ts
|
|
659
|
-
import * as
|
|
660
|
-
import * as
|
|
723
|
+
import * as fs6 from "fs/promises";
|
|
724
|
+
import * as path6 from "path";
|
|
661
725
|
import { Command as Command7 } from "commander";
|
|
662
726
|
async function getDirSize(dirPath) {
|
|
663
727
|
let size = 0;
|
|
664
|
-
const files = await
|
|
728
|
+
const files = await fs6.readdir(dirPath, { withFileTypes: true });
|
|
665
729
|
for (const file of files) {
|
|
666
|
-
const fullPath =
|
|
730
|
+
const fullPath = path6.join(dirPath, file.name);
|
|
667
731
|
if (file.isDirectory()) {
|
|
668
732
|
size += await getDirSize(fullPath);
|
|
669
733
|
} else {
|
|
670
|
-
const stats = await
|
|
734
|
+
const stats = await fs6.stat(fullPath);
|
|
671
735
|
size += stats.size;
|
|
672
736
|
}
|
|
673
737
|
}
|
|
674
738
|
return size;
|
|
675
739
|
}
|
|
676
740
|
var infoCommand = new Command7("info").description("Displays size and file statistics of the built package").action(async () => {
|
|
741
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
677
742
|
const cwd = process.cwd();
|
|
678
|
-
const pkgJsonPath =
|
|
743
|
+
const pkgJsonPath = path6.join(cwd, "package.json");
|
|
679
744
|
try {
|
|
680
|
-
const packageJsonContent = await
|
|
745
|
+
const packageJsonContent = await fs6.readFile(pkgJsonPath, {
|
|
681
746
|
encoding: "utf8"
|
|
682
747
|
});
|
|
683
748
|
const packageJson = JSON.parse(packageJsonContent);
|
|
@@ -685,10 +750,11 @@ var infoCommand = new Command7("info").description("Displays size and file stati
|
|
|
685
750
|
if (!publishDirBase) {
|
|
686
751
|
throw new Error(`No publish directory specified in package.json.`);
|
|
687
752
|
}
|
|
688
|
-
const publishDir =
|
|
753
|
+
const publishDir = path6.join(cwd, publishDirBase);
|
|
689
754
|
const sizeBytes = await getDirSize(publishDir);
|
|
690
755
|
const sizeKB = (sizeBytes / 1024).toFixed(2);
|
|
691
756
|
const sizeMB = (sizeBytes / (1024 * 1024)).toFixed(2);
|
|
757
|
+
if (isVerbose) console.log(`Gathering info from ${publishDir}...`);
|
|
692
758
|
console.log(`
|
|
693
759
|
\u{1F4CA} Package Info: ${packageJson.name}`);
|
|
694
760
|
console.log(`================================`);
|
|
@@ -712,17 +778,19 @@ var infoCommand = new Command7("info").description("Displays size and file stati
|
|
|
712
778
|
});
|
|
713
779
|
|
|
714
780
|
// src/core/link.ts
|
|
715
|
-
import * as
|
|
716
|
-
import * as
|
|
781
|
+
import * as fs7 from "fs/promises";
|
|
782
|
+
import * as path7 from "path";
|
|
717
783
|
import { Command as Command8 } from "commander";
|
|
718
784
|
import { $ as $6 } from "execa";
|
|
719
785
|
var linkCommand = new Command8("link").description(
|
|
720
786
|
"Symlinks the built package directory so it can be tested in other local projects"
|
|
721
787
|
).action(async () => {
|
|
788
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
789
|
+
const pm = getPackageManager();
|
|
722
790
|
const cwd = process.cwd();
|
|
723
|
-
const pkgJsonPath =
|
|
791
|
+
const pkgJsonPath = path7.join(cwd, "package.json");
|
|
724
792
|
try {
|
|
725
|
-
const packageJsonContent = await
|
|
793
|
+
const packageJsonContent = await fs7.readFile(pkgJsonPath, {
|
|
726
794
|
encoding: "utf8"
|
|
727
795
|
});
|
|
728
796
|
const packageJson = JSON.parse(packageJsonContent);
|
|
@@ -730,18 +798,19 @@ var linkCommand = new Command8("link").description(
|
|
|
730
798
|
if (!publishDirBase) {
|
|
731
799
|
throw new Error(`No publish directory specified in package.json.`);
|
|
732
800
|
}
|
|
733
|
-
const publishDir =
|
|
734
|
-
|
|
801
|
+
const publishDir = path7.join(cwd, publishDirBase);
|
|
802
|
+
if (isVerbose)
|
|
803
|
+
console.log(`\u{1F517} Linking package from: ./${publishDirBase}...`);
|
|
735
804
|
await $6({
|
|
736
|
-
stdio: "inherit",
|
|
805
|
+
stdio: isVerbose ? "inherit" : "pipe",
|
|
737
806
|
cwd: publishDir
|
|
738
|
-
})
|
|
807
|
+
})`${pm} link`;
|
|
739
808
|
console.log(`
|
|
740
809
|
\u2705 Successfully linked!`);
|
|
741
810
|
console.log(
|
|
742
811
|
`To use this in another project, go to that project and run:`
|
|
743
812
|
);
|
|
744
|
-
console.log(`\u{1F449}
|
|
813
|
+
console.log(`\u{1F449} ${pm} link ${packageJson.name}`);
|
|
745
814
|
} catch (error) {
|
|
746
815
|
console.error("\u274C Error executing link command:");
|
|
747
816
|
if (error instanceof Error) console.error(error.message);
|
|
@@ -750,11 +819,11 @@ var linkCommand = new Command8("link").description(
|
|
|
750
819
|
});
|
|
751
820
|
|
|
752
821
|
// src/core/check-exports.ts
|
|
753
|
-
import * as
|
|
754
|
-
import * as
|
|
822
|
+
import * as fs8 from "fs/promises";
|
|
823
|
+
import * as path8 from "path";
|
|
755
824
|
import { Command as Command9 } from "commander";
|
|
756
825
|
async function fileExists(filePath) {
|
|
757
|
-
return
|
|
826
|
+
return fs8.stat(filePath).then(() => true).catch(() => false);
|
|
758
827
|
}
|
|
759
828
|
function extractPaths(exportsObj) {
|
|
760
829
|
let paths = [];
|
|
@@ -771,35 +840,36 @@ function extractPaths(exportsObj) {
|
|
|
771
840
|
var checkExportsCommand = new Command9("check-exports").description(
|
|
772
841
|
"Verifies that all files declared in package.json 'exports' actually exist in the build folder"
|
|
773
842
|
).action(async () => {
|
|
843
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
774
844
|
const cwd = process.cwd();
|
|
775
|
-
const pkgJsonPath =
|
|
845
|
+
const pkgJsonPath = path8.join(cwd, "package.json");
|
|
776
846
|
try {
|
|
777
|
-
const rootPkgContent = await
|
|
847
|
+
const rootPkgContent = await fs8.readFile(pkgJsonPath, {
|
|
778
848
|
encoding: "utf8"
|
|
779
849
|
});
|
|
780
850
|
const publishDirBase = JSON.parse(rootPkgContent).publishConfig?.directory || "build";
|
|
781
|
-
const buildPkgPath =
|
|
851
|
+
const buildPkgPath = path8.join(cwd, publishDirBase, "package.json");
|
|
782
852
|
if (!await fileExists(buildPkgPath)) {
|
|
783
853
|
throw new Error(
|
|
784
854
|
`Could not find compiled package.json at ./${publishDirBase}/package.json. Did you build first?`
|
|
785
855
|
);
|
|
786
856
|
}
|
|
787
|
-
const buildPkgContent = await
|
|
857
|
+
const buildPkgContent = await fs8.readFile(buildPkgPath, {
|
|
788
858
|
encoding: "utf8"
|
|
789
859
|
});
|
|
790
860
|
const buildPkg = JSON.parse(buildPkgContent);
|
|
791
861
|
if (!buildPkg.exports) {
|
|
792
|
-
console.log("\u26A0\uFE0F No 'exports' field found to check.");
|
|
862
|
+
if (isVerbose) console.log("\u26A0\uFE0F No 'exports' field found to check.");
|
|
793
863
|
return;
|
|
794
864
|
}
|
|
795
865
|
console.log(`\u{1F575}\uFE0F Checking exports mapping in ./${publishDirBase}...`);
|
|
796
866
|
const allPaths = extractPaths(buildPkg.exports);
|
|
797
867
|
let hasErrors = false;
|
|
798
868
|
for (const relativePath of allPaths) {
|
|
799
|
-
const absolutePath =
|
|
869
|
+
const absolutePath = path8.join(cwd, publishDirBase, relativePath);
|
|
800
870
|
const exists = await fileExists(absolutePath);
|
|
801
871
|
if (exists) {
|
|
802
|
-
console.log(` \u2705 Found: ${relativePath}`);
|
|
872
|
+
if (isVerbose) console.log(` \u2705 Found: ${relativePath}`);
|
|
803
873
|
} else {
|
|
804
874
|
console.error(` \u274C Missing: ${relativePath}`);
|
|
805
875
|
hasErrors = true;
|
|
@@ -820,7 +890,8 @@ var checkExportsCommand = new Command9("check-exports").description(
|
|
|
820
890
|
});
|
|
821
891
|
|
|
822
892
|
// src/core/watch.ts
|
|
823
|
-
import * as
|
|
893
|
+
import * as fs9 from "fs/promises";
|
|
894
|
+
import * as path9 from "path";
|
|
824
895
|
import { Command as Command10 } from "commander";
|
|
825
896
|
|
|
826
897
|
// node_modules/chokidar/index.js
|
|
@@ -913,7 +984,7 @@ var ReaddirpStream = class extends Readable {
|
|
|
913
984
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
914
985
|
const statMethod = opts.lstat ? lstat : stat5;
|
|
915
986
|
if (wantBigintFsStats) {
|
|
916
|
-
this._stat = (
|
|
987
|
+
this._stat = (path10) => statMethod(path10, { bigint: true });
|
|
917
988
|
} else {
|
|
918
989
|
this._stat = statMethod;
|
|
919
990
|
}
|
|
@@ -938,8 +1009,8 @@ var ReaddirpStream = class extends Readable {
|
|
|
938
1009
|
const par = this.parent;
|
|
939
1010
|
const fil = par && par.files;
|
|
940
1011
|
if (fil && fil.length > 0) {
|
|
941
|
-
const { path:
|
|
942
|
-
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent,
|
|
1012
|
+
const { path: path10, depth } = par;
|
|
1013
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path10));
|
|
943
1014
|
const awaited = await Promise.all(slice);
|
|
944
1015
|
for (const entry of awaited) {
|
|
945
1016
|
if (!entry)
|
|
@@ -979,20 +1050,20 @@ var ReaddirpStream = class extends Readable {
|
|
|
979
1050
|
this.reading = false;
|
|
980
1051
|
}
|
|
981
1052
|
}
|
|
982
|
-
async _exploreDir(
|
|
1053
|
+
async _exploreDir(path10, depth) {
|
|
983
1054
|
let files;
|
|
984
1055
|
try {
|
|
985
|
-
files = await readdir2(
|
|
1056
|
+
files = await readdir2(path10, this._rdOptions);
|
|
986
1057
|
} catch (error) {
|
|
987
1058
|
this._onError(error);
|
|
988
1059
|
}
|
|
989
|
-
return { files, depth, path:
|
|
1060
|
+
return { files, depth, path: path10 };
|
|
990
1061
|
}
|
|
991
|
-
async _formatEntry(dirent,
|
|
1062
|
+
async _formatEntry(dirent, path10) {
|
|
992
1063
|
let entry;
|
|
993
1064
|
const basename4 = this._isDirent ? dirent.name : dirent;
|
|
994
1065
|
try {
|
|
995
|
-
const fullPath = presolve(pjoin(
|
|
1066
|
+
const fullPath = presolve(pjoin(path10, basename4));
|
|
996
1067
|
entry = { path: prelative(this._root, fullPath), fullPath, basename: basename4 };
|
|
997
1068
|
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
998
1069
|
} catch (err) {
|
|
@@ -1392,16 +1463,16 @@ var delFromSet = (main2, prop, item) => {
|
|
|
1392
1463
|
};
|
|
1393
1464
|
var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
1394
1465
|
var FsWatchInstances = /* @__PURE__ */ new Map();
|
|
1395
|
-
function createFsWatchInstance(
|
|
1466
|
+
function createFsWatchInstance(path10, options, listener, errHandler, emitRaw) {
|
|
1396
1467
|
const handleEvent = (rawEvent, evPath) => {
|
|
1397
|
-
listener(
|
|
1398
|
-
emitRaw(rawEvent, evPath, { watchedPath:
|
|
1399
|
-
if (evPath &&
|
|
1400
|
-
fsWatchBroadcast(sp.resolve(
|
|
1468
|
+
listener(path10);
|
|
1469
|
+
emitRaw(rawEvent, evPath, { watchedPath: path10 });
|
|
1470
|
+
if (evPath && path10 !== evPath) {
|
|
1471
|
+
fsWatchBroadcast(sp.resolve(path10, evPath), KEY_LISTENERS, sp.join(path10, evPath));
|
|
1401
1472
|
}
|
|
1402
1473
|
};
|
|
1403
1474
|
try {
|
|
1404
|
-
return fs_watch(
|
|
1475
|
+
return fs_watch(path10, {
|
|
1405
1476
|
persistent: options.persistent
|
|
1406
1477
|
}, handleEvent);
|
|
1407
1478
|
} catch (error) {
|
|
@@ -1417,12 +1488,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
|
1417
1488
|
listener(val1, val2, val3);
|
|
1418
1489
|
});
|
|
1419
1490
|
};
|
|
1420
|
-
var setFsWatchListener = (
|
|
1491
|
+
var setFsWatchListener = (path10, fullPath, options, handlers) => {
|
|
1421
1492
|
const { listener, errHandler, rawEmitter } = handlers;
|
|
1422
1493
|
let cont = FsWatchInstances.get(fullPath);
|
|
1423
1494
|
let watcher;
|
|
1424
1495
|
if (!options.persistent) {
|
|
1425
|
-
watcher = createFsWatchInstance(
|
|
1496
|
+
watcher = createFsWatchInstance(path10, options, listener, errHandler, rawEmitter);
|
|
1426
1497
|
if (!watcher)
|
|
1427
1498
|
return;
|
|
1428
1499
|
return watcher.close.bind(watcher);
|
|
@@ -1433,7 +1504,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
1433
1504
|
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
1434
1505
|
} else {
|
|
1435
1506
|
watcher = createFsWatchInstance(
|
|
1436
|
-
|
|
1507
|
+
path10,
|
|
1437
1508
|
options,
|
|
1438
1509
|
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
1439
1510
|
errHandler,
|
|
@@ -1448,7 +1519,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
1448
1519
|
cont.watcherUnusable = true;
|
|
1449
1520
|
if (isWindows && error.code === "EPERM") {
|
|
1450
1521
|
try {
|
|
1451
|
-
const fd = await open(
|
|
1522
|
+
const fd = await open(path10, "r");
|
|
1452
1523
|
await fd.close();
|
|
1453
1524
|
broadcastErr(error);
|
|
1454
1525
|
} catch (err) {
|
|
@@ -1479,7 +1550,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
1479
1550
|
};
|
|
1480
1551
|
};
|
|
1481
1552
|
var FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
1482
|
-
var setFsWatchFileListener = (
|
|
1553
|
+
var setFsWatchFileListener = (path10, fullPath, options, handlers) => {
|
|
1483
1554
|
const { listener, rawEmitter } = handlers;
|
|
1484
1555
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
1485
1556
|
const copts = cont && cont.options;
|
|
@@ -1501,7 +1572,7 @@ var setFsWatchFileListener = (path9, fullPath, options, handlers) => {
|
|
|
1501
1572
|
});
|
|
1502
1573
|
const currmtime = curr.mtimeMs;
|
|
1503
1574
|
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
1504
|
-
foreach(cont.listeners, (listener2) => listener2(
|
|
1575
|
+
foreach(cont.listeners, (listener2) => listener2(path10, curr));
|
|
1505
1576
|
}
|
|
1506
1577
|
})
|
|
1507
1578
|
};
|
|
@@ -1531,13 +1602,13 @@ var NodeFsHandler = class {
|
|
|
1531
1602
|
* @param listener on fs change
|
|
1532
1603
|
* @returns closer for the watcher instance
|
|
1533
1604
|
*/
|
|
1534
|
-
_watchWithNodeFs(
|
|
1605
|
+
_watchWithNodeFs(path10, listener) {
|
|
1535
1606
|
const opts = this.fsw.options;
|
|
1536
|
-
const directory = sp.dirname(
|
|
1537
|
-
const basename4 = sp.basename(
|
|
1607
|
+
const directory = sp.dirname(path10);
|
|
1608
|
+
const basename4 = sp.basename(path10);
|
|
1538
1609
|
const parent = this.fsw._getWatchedDir(directory);
|
|
1539
1610
|
parent.add(basename4);
|
|
1540
|
-
const absolutePath = sp.resolve(
|
|
1611
|
+
const absolutePath = sp.resolve(path10);
|
|
1541
1612
|
const options = {
|
|
1542
1613
|
persistent: opts.persistent
|
|
1543
1614
|
};
|
|
@@ -1547,12 +1618,12 @@ var NodeFsHandler = class {
|
|
|
1547
1618
|
if (opts.usePolling) {
|
|
1548
1619
|
const enableBin = opts.interval !== opts.binaryInterval;
|
|
1549
1620
|
options.interval = enableBin && isBinaryPath(basename4) ? opts.binaryInterval : opts.interval;
|
|
1550
|
-
closer = setFsWatchFileListener(
|
|
1621
|
+
closer = setFsWatchFileListener(path10, absolutePath, options, {
|
|
1551
1622
|
listener,
|
|
1552
1623
|
rawEmitter: this.fsw._emitRaw
|
|
1553
1624
|
});
|
|
1554
1625
|
} else {
|
|
1555
|
-
closer = setFsWatchListener(
|
|
1626
|
+
closer = setFsWatchListener(path10, absolutePath, options, {
|
|
1556
1627
|
listener,
|
|
1557
1628
|
errHandler: this._boundHandleError,
|
|
1558
1629
|
rawEmitter: this.fsw._emitRaw
|
|
@@ -1568,13 +1639,13 @@ var NodeFsHandler = class {
|
|
|
1568
1639
|
if (this.fsw.closed) {
|
|
1569
1640
|
return;
|
|
1570
1641
|
}
|
|
1571
|
-
const
|
|
1642
|
+
const dirname5 = sp.dirname(file);
|
|
1572
1643
|
const basename4 = sp.basename(file);
|
|
1573
|
-
const parent = this.fsw._getWatchedDir(
|
|
1644
|
+
const parent = this.fsw._getWatchedDir(dirname5);
|
|
1574
1645
|
let prevStats = stats;
|
|
1575
1646
|
if (parent.has(basename4))
|
|
1576
1647
|
return;
|
|
1577
|
-
const listener = async (
|
|
1648
|
+
const listener = async (path10, newStats) => {
|
|
1578
1649
|
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
1579
1650
|
return;
|
|
1580
1651
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
@@ -1588,16 +1659,16 @@ var NodeFsHandler = class {
|
|
|
1588
1659
|
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
1589
1660
|
}
|
|
1590
1661
|
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
1591
|
-
this.fsw._closeFile(
|
|
1662
|
+
this.fsw._closeFile(path10);
|
|
1592
1663
|
prevStats = newStats2;
|
|
1593
1664
|
const closer2 = this._watchWithNodeFs(file, listener);
|
|
1594
1665
|
if (closer2)
|
|
1595
|
-
this.fsw._addPathCloser(
|
|
1666
|
+
this.fsw._addPathCloser(path10, closer2);
|
|
1596
1667
|
} else {
|
|
1597
1668
|
prevStats = newStats2;
|
|
1598
1669
|
}
|
|
1599
1670
|
} catch (error) {
|
|
1600
|
-
this.fsw._remove(
|
|
1671
|
+
this.fsw._remove(dirname5, basename4);
|
|
1601
1672
|
}
|
|
1602
1673
|
} else if (parent.has(basename4)) {
|
|
1603
1674
|
const at = newStats.atimeMs;
|
|
@@ -1624,7 +1695,7 @@ var NodeFsHandler = class {
|
|
|
1624
1695
|
* @param item basename of this item
|
|
1625
1696
|
* @returns true if no more processing is needed for this entry.
|
|
1626
1697
|
*/
|
|
1627
|
-
async _handleSymlink(entry, directory,
|
|
1698
|
+
async _handleSymlink(entry, directory, path10, item) {
|
|
1628
1699
|
if (this.fsw.closed) {
|
|
1629
1700
|
return;
|
|
1630
1701
|
}
|
|
@@ -1634,7 +1705,7 @@ var NodeFsHandler = class {
|
|
|
1634
1705
|
this.fsw._incrReadyCount();
|
|
1635
1706
|
let linkPath;
|
|
1636
1707
|
try {
|
|
1637
|
-
linkPath = await fsrealpath(
|
|
1708
|
+
linkPath = await fsrealpath(path10);
|
|
1638
1709
|
} catch (e) {
|
|
1639
1710
|
this.fsw._emitReady();
|
|
1640
1711
|
return true;
|
|
@@ -1644,12 +1715,12 @@ var NodeFsHandler = class {
|
|
|
1644
1715
|
if (dir.has(item)) {
|
|
1645
1716
|
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
1646
1717
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
1647
|
-
this.fsw._emit(EV.CHANGE,
|
|
1718
|
+
this.fsw._emit(EV.CHANGE, path10, entry.stats);
|
|
1648
1719
|
}
|
|
1649
1720
|
} else {
|
|
1650
1721
|
dir.add(item);
|
|
1651
1722
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
1652
|
-
this.fsw._emit(EV.ADD,
|
|
1723
|
+
this.fsw._emit(EV.ADD, path10, entry.stats);
|
|
1653
1724
|
}
|
|
1654
1725
|
this.fsw._emitReady();
|
|
1655
1726
|
return true;
|
|
@@ -1679,9 +1750,9 @@ var NodeFsHandler = class {
|
|
|
1679
1750
|
return;
|
|
1680
1751
|
}
|
|
1681
1752
|
const item = entry.path;
|
|
1682
|
-
let
|
|
1753
|
+
let path10 = sp.join(directory, item);
|
|
1683
1754
|
current.add(item);
|
|
1684
|
-
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory,
|
|
1755
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path10, item)) {
|
|
1685
1756
|
return;
|
|
1686
1757
|
}
|
|
1687
1758
|
if (this.fsw.closed) {
|
|
@@ -1690,8 +1761,8 @@ var NodeFsHandler = class {
|
|
|
1690
1761
|
}
|
|
1691
1762
|
if (item === target || !target && !previous.has(item)) {
|
|
1692
1763
|
this.fsw._incrReadyCount();
|
|
1693
|
-
|
|
1694
|
-
this._addToNodeFs(
|
|
1764
|
+
path10 = sp.join(dir, sp.relative(dir, path10));
|
|
1765
|
+
this._addToNodeFs(path10, initialAdd, wh, depth + 1);
|
|
1695
1766
|
}
|
|
1696
1767
|
}).on(EV.ERROR, this._boundHandleError);
|
|
1697
1768
|
return new Promise((resolve4, reject) => {
|
|
@@ -1760,13 +1831,13 @@ var NodeFsHandler = class {
|
|
|
1760
1831
|
* @param depth Child path actually targeted for watch
|
|
1761
1832
|
* @param target Child path actually targeted for watch
|
|
1762
1833
|
*/
|
|
1763
|
-
async _addToNodeFs(
|
|
1834
|
+
async _addToNodeFs(path10, initialAdd, priorWh, depth, target) {
|
|
1764
1835
|
const ready = this.fsw._emitReady;
|
|
1765
|
-
if (this.fsw._isIgnored(
|
|
1836
|
+
if (this.fsw._isIgnored(path10) || this.fsw.closed) {
|
|
1766
1837
|
ready();
|
|
1767
1838
|
return false;
|
|
1768
1839
|
}
|
|
1769
|
-
const wh = this.fsw._getWatchHelpers(
|
|
1840
|
+
const wh = this.fsw._getWatchHelpers(path10);
|
|
1770
1841
|
if (priorWh) {
|
|
1771
1842
|
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
1772
1843
|
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
@@ -1782,8 +1853,8 @@ var NodeFsHandler = class {
|
|
|
1782
1853
|
const follow = this.fsw.options.followSymlinks;
|
|
1783
1854
|
let closer;
|
|
1784
1855
|
if (stats.isDirectory()) {
|
|
1785
|
-
const absPath = sp.resolve(
|
|
1786
|
-
const targetPath = follow ? await fsrealpath(
|
|
1856
|
+
const absPath = sp.resolve(path10);
|
|
1857
|
+
const targetPath = follow ? await fsrealpath(path10) : path10;
|
|
1787
1858
|
if (this.fsw.closed)
|
|
1788
1859
|
return;
|
|
1789
1860
|
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
@@ -1793,29 +1864,29 @@ var NodeFsHandler = class {
|
|
|
1793
1864
|
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
1794
1865
|
}
|
|
1795
1866
|
} else if (stats.isSymbolicLink()) {
|
|
1796
|
-
const targetPath = follow ? await fsrealpath(
|
|
1867
|
+
const targetPath = follow ? await fsrealpath(path10) : path10;
|
|
1797
1868
|
if (this.fsw.closed)
|
|
1798
1869
|
return;
|
|
1799
1870
|
const parent = sp.dirname(wh.watchPath);
|
|
1800
1871
|
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
1801
1872
|
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
1802
|
-
closer = await this._handleDir(parent, stats, initialAdd, depth,
|
|
1873
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path10, wh, targetPath);
|
|
1803
1874
|
if (this.fsw.closed)
|
|
1804
1875
|
return;
|
|
1805
1876
|
if (targetPath !== void 0) {
|
|
1806
|
-
this.fsw._symlinkPaths.set(sp.resolve(
|
|
1877
|
+
this.fsw._symlinkPaths.set(sp.resolve(path10), targetPath);
|
|
1807
1878
|
}
|
|
1808
1879
|
} else {
|
|
1809
1880
|
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
1810
1881
|
}
|
|
1811
1882
|
ready();
|
|
1812
1883
|
if (closer)
|
|
1813
|
-
this.fsw._addPathCloser(
|
|
1884
|
+
this.fsw._addPathCloser(path10, closer);
|
|
1814
1885
|
return false;
|
|
1815
1886
|
} catch (error) {
|
|
1816
1887
|
if (this.fsw._handleError(error)) {
|
|
1817
1888
|
ready();
|
|
1818
|
-
return
|
|
1889
|
+
return path10;
|
|
1819
1890
|
}
|
|
1820
1891
|
}
|
|
1821
1892
|
}
|
|
@@ -1847,35 +1918,35 @@ function createPattern(matcher) {
|
|
|
1847
1918
|
if (matcher.path === string)
|
|
1848
1919
|
return true;
|
|
1849
1920
|
if (matcher.recursive) {
|
|
1850
|
-
const
|
|
1851
|
-
if (!
|
|
1921
|
+
const relative4 = sp2.relative(matcher.path, string);
|
|
1922
|
+
if (!relative4) {
|
|
1852
1923
|
return false;
|
|
1853
1924
|
}
|
|
1854
|
-
return !
|
|
1925
|
+
return !relative4.startsWith("..") && !sp2.isAbsolute(relative4);
|
|
1855
1926
|
}
|
|
1856
1927
|
return false;
|
|
1857
1928
|
};
|
|
1858
1929
|
}
|
|
1859
1930
|
return () => false;
|
|
1860
1931
|
}
|
|
1861
|
-
function normalizePath(
|
|
1862
|
-
if (typeof
|
|
1932
|
+
function normalizePath(path10) {
|
|
1933
|
+
if (typeof path10 !== "string")
|
|
1863
1934
|
throw new Error("string expected");
|
|
1864
|
-
|
|
1865
|
-
|
|
1935
|
+
path10 = sp2.normalize(path10);
|
|
1936
|
+
path10 = path10.replace(/\\/g, "/");
|
|
1866
1937
|
let prepend = false;
|
|
1867
|
-
if (
|
|
1938
|
+
if (path10.startsWith("//"))
|
|
1868
1939
|
prepend = true;
|
|
1869
|
-
|
|
1940
|
+
path10 = path10.replace(DOUBLE_SLASH_RE, "/");
|
|
1870
1941
|
if (prepend)
|
|
1871
|
-
|
|
1872
|
-
return
|
|
1942
|
+
path10 = "/" + path10;
|
|
1943
|
+
return path10;
|
|
1873
1944
|
}
|
|
1874
1945
|
function matchPatterns(patterns, testString, stats) {
|
|
1875
|
-
const
|
|
1946
|
+
const path10 = normalizePath(testString);
|
|
1876
1947
|
for (let index = 0; index < patterns.length; index++) {
|
|
1877
1948
|
const pattern = patterns[index];
|
|
1878
|
-
if (pattern(
|
|
1949
|
+
if (pattern(path10, stats)) {
|
|
1879
1950
|
return true;
|
|
1880
1951
|
}
|
|
1881
1952
|
}
|
|
@@ -1913,19 +1984,19 @@ var toUnix = (string) => {
|
|
|
1913
1984
|
}
|
|
1914
1985
|
return str;
|
|
1915
1986
|
};
|
|
1916
|
-
var normalizePathToUnix = (
|
|
1917
|
-
var normalizeIgnored = (cwd = "") => (
|
|
1918
|
-
if (typeof
|
|
1919
|
-
return normalizePathToUnix(sp2.isAbsolute(
|
|
1987
|
+
var normalizePathToUnix = (path10) => toUnix(sp2.normalize(toUnix(path10)));
|
|
1988
|
+
var normalizeIgnored = (cwd = "") => (path10) => {
|
|
1989
|
+
if (typeof path10 === "string") {
|
|
1990
|
+
return normalizePathToUnix(sp2.isAbsolute(path10) ? path10 : sp2.join(cwd, path10));
|
|
1920
1991
|
} else {
|
|
1921
|
-
return
|
|
1992
|
+
return path10;
|
|
1922
1993
|
}
|
|
1923
1994
|
};
|
|
1924
|
-
var getAbsolutePath = (
|
|
1925
|
-
if (sp2.isAbsolute(
|
|
1926
|
-
return
|
|
1995
|
+
var getAbsolutePath = (path10, cwd) => {
|
|
1996
|
+
if (sp2.isAbsolute(path10)) {
|
|
1997
|
+
return path10;
|
|
1927
1998
|
}
|
|
1928
|
-
return sp2.join(cwd,
|
|
1999
|
+
return sp2.join(cwd, path10);
|
|
1929
2000
|
};
|
|
1930
2001
|
var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
1931
2002
|
var DirEntry = class {
|
|
@@ -1990,10 +2061,10 @@ var WatchHelper = class {
|
|
|
1990
2061
|
dirParts;
|
|
1991
2062
|
followSymlinks;
|
|
1992
2063
|
statMethod;
|
|
1993
|
-
constructor(
|
|
2064
|
+
constructor(path10, follow, fsw) {
|
|
1994
2065
|
this.fsw = fsw;
|
|
1995
|
-
const watchPath =
|
|
1996
|
-
this.path =
|
|
2066
|
+
const watchPath = path10;
|
|
2067
|
+
this.path = path10 = path10.replace(REPLACER_RE, "");
|
|
1997
2068
|
this.watchPath = watchPath;
|
|
1998
2069
|
this.fullWatchPath = sp2.resolve(watchPath);
|
|
1999
2070
|
this.dirParts = [];
|
|
@@ -2133,20 +2204,20 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2133
2204
|
this._closePromise = void 0;
|
|
2134
2205
|
let paths = unifyPaths(paths_);
|
|
2135
2206
|
if (cwd) {
|
|
2136
|
-
paths = paths.map((
|
|
2137
|
-
const absPath = getAbsolutePath(
|
|
2207
|
+
paths = paths.map((path10) => {
|
|
2208
|
+
const absPath = getAbsolutePath(path10, cwd);
|
|
2138
2209
|
return absPath;
|
|
2139
2210
|
});
|
|
2140
2211
|
}
|
|
2141
|
-
paths.forEach((
|
|
2142
|
-
this._removeIgnoredPath(
|
|
2212
|
+
paths.forEach((path10) => {
|
|
2213
|
+
this._removeIgnoredPath(path10);
|
|
2143
2214
|
});
|
|
2144
2215
|
this._userIgnored = void 0;
|
|
2145
2216
|
if (!this._readyCount)
|
|
2146
2217
|
this._readyCount = 0;
|
|
2147
2218
|
this._readyCount += paths.length;
|
|
2148
|
-
Promise.all(paths.map(async (
|
|
2149
|
-
const res = await this._nodeFsHandler._addToNodeFs(
|
|
2219
|
+
Promise.all(paths.map(async (path10) => {
|
|
2220
|
+
const res = await this._nodeFsHandler._addToNodeFs(path10, !_internal, void 0, 0, _origAdd);
|
|
2150
2221
|
if (res)
|
|
2151
2222
|
this._emitReady();
|
|
2152
2223
|
return res;
|
|
@@ -2168,17 +2239,17 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2168
2239
|
return this;
|
|
2169
2240
|
const paths = unifyPaths(paths_);
|
|
2170
2241
|
const { cwd } = this.options;
|
|
2171
|
-
paths.forEach((
|
|
2172
|
-
if (!sp2.isAbsolute(
|
|
2242
|
+
paths.forEach((path10) => {
|
|
2243
|
+
if (!sp2.isAbsolute(path10) && !this._closers.has(path10)) {
|
|
2173
2244
|
if (cwd)
|
|
2174
|
-
|
|
2175
|
-
|
|
2245
|
+
path10 = sp2.join(cwd, path10);
|
|
2246
|
+
path10 = sp2.resolve(path10);
|
|
2176
2247
|
}
|
|
2177
|
-
this._closePath(
|
|
2178
|
-
this._addIgnoredPath(
|
|
2179
|
-
if (this._watched.has(
|
|
2248
|
+
this._closePath(path10);
|
|
2249
|
+
this._addIgnoredPath(path10);
|
|
2250
|
+
if (this._watched.has(path10)) {
|
|
2180
2251
|
this._addIgnoredPath({
|
|
2181
|
-
path:
|
|
2252
|
+
path: path10,
|
|
2182
2253
|
recursive: true
|
|
2183
2254
|
});
|
|
2184
2255
|
}
|
|
@@ -2242,38 +2313,38 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2242
2313
|
* @param stats arguments to be passed with event
|
|
2243
2314
|
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
2244
2315
|
*/
|
|
2245
|
-
async _emit(event,
|
|
2316
|
+
async _emit(event, path10, stats) {
|
|
2246
2317
|
if (this.closed)
|
|
2247
2318
|
return;
|
|
2248
2319
|
const opts = this.options;
|
|
2249
2320
|
if (isWindows)
|
|
2250
|
-
|
|
2321
|
+
path10 = sp2.normalize(path10);
|
|
2251
2322
|
if (opts.cwd)
|
|
2252
|
-
|
|
2253
|
-
const args = [
|
|
2323
|
+
path10 = sp2.relative(opts.cwd, path10);
|
|
2324
|
+
const args = [path10];
|
|
2254
2325
|
if (stats != null)
|
|
2255
2326
|
args.push(stats);
|
|
2256
2327
|
const awf = opts.awaitWriteFinish;
|
|
2257
2328
|
let pw;
|
|
2258
|
-
if (awf && (pw = this._pendingWrites.get(
|
|
2329
|
+
if (awf && (pw = this._pendingWrites.get(path10))) {
|
|
2259
2330
|
pw.lastChange = /* @__PURE__ */ new Date();
|
|
2260
2331
|
return this;
|
|
2261
2332
|
}
|
|
2262
2333
|
if (opts.atomic) {
|
|
2263
2334
|
if (event === EVENTS.UNLINK) {
|
|
2264
|
-
this._pendingUnlinks.set(
|
|
2335
|
+
this._pendingUnlinks.set(path10, [event, ...args]);
|
|
2265
2336
|
setTimeout(() => {
|
|
2266
|
-
this._pendingUnlinks.forEach((entry,
|
|
2337
|
+
this._pendingUnlinks.forEach((entry, path11) => {
|
|
2267
2338
|
this.emit(...entry);
|
|
2268
2339
|
this.emit(EVENTS.ALL, ...entry);
|
|
2269
|
-
this._pendingUnlinks.delete(
|
|
2340
|
+
this._pendingUnlinks.delete(path11);
|
|
2270
2341
|
});
|
|
2271
2342
|
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
2272
2343
|
return this;
|
|
2273
2344
|
}
|
|
2274
|
-
if (event === EVENTS.ADD && this._pendingUnlinks.has(
|
|
2345
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path10)) {
|
|
2275
2346
|
event = EVENTS.CHANGE;
|
|
2276
|
-
this._pendingUnlinks.delete(
|
|
2347
|
+
this._pendingUnlinks.delete(path10);
|
|
2277
2348
|
}
|
|
2278
2349
|
}
|
|
2279
2350
|
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
@@ -2291,16 +2362,16 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2291
2362
|
this.emitWithAll(event, args);
|
|
2292
2363
|
}
|
|
2293
2364
|
};
|
|
2294
|
-
this._awaitWriteFinish(
|
|
2365
|
+
this._awaitWriteFinish(path10, awf.stabilityThreshold, event, awfEmit);
|
|
2295
2366
|
return this;
|
|
2296
2367
|
}
|
|
2297
2368
|
if (event === EVENTS.CHANGE) {
|
|
2298
|
-
const isThrottled = !this._throttle(EVENTS.CHANGE,
|
|
2369
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path10, 50);
|
|
2299
2370
|
if (isThrottled)
|
|
2300
2371
|
return this;
|
|
2301
2372
|
}
|
|
2302
2373
|
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
2303
|
-
const fullPath = opts.cwd ? sp2.join(opts.cwd,
|
|
2374
|
+
const fullPath = opts.cwd ? sp2.join(opts.cwd, path10) : path10;
|
|
2304
2375
|
let stats2;
|
|
2305
2376
|
try {
|
|
2306
2377
|
stats2 = await stat7(fullPath);
|
|
@@ -2331,23 +2402,23 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2331
2402
|
* @param timeout duration of time to suppress duplicate actions
|
|
2332
2403
|
* @returns tracking object or false if action should be suppressed
|
|
2333
2404
|
*/
|
|
2334
|
-
_throttle(actionType,
|
|
2405
|
+
_throttle(actionType, path10, timeout) {
|
|
2335
2406
|
if (!this._throttled.has(actionType)) {
|
|
2336
2407
|
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
2337
2408
|
}
|
|
2338
2409
|
const action = this._throttled.get(actionType);
|
|
2339
2410
|
if (!action)
|
|
2340
2411
|
throw new Error("invalid throttle");
|
|
2341
|
-
const actionPath = action.get(
|
|
2412
|
+
const actionPath = action.get(path10);
|
|
2342
2413
|
if (actionPath) {
|
|
2343
2414
|
actionPath.count++;
|
|
2344
2415
|
return false;
|
|
2345
2416
|
}
|
|
2346
2417
|
let timeoutObject;
|
|
2347
2418
|
const clear = () => {
|
|
2348
|
-
const item = action.get(
|
|
2419
|
+
const item = action.get(path10);
|
|
2349
2420
|
const count = item ? item.count : 0;
|
|
2350
|
-
action.delete(
|
|
2421
|
+
action.delete(path10);
|
|
2351
2422
|
clearTimeout(timeoutObject);
|
|
2352
2423
|
if (item)
|
|
2353
2424
|
clearTimeout(item.timeoutObject);
|
|
@@ -2355,7 +2426,7 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2355
2426
|
};
|
|
2356
2427
|
timeoutObject = setTimeout(clear, timeout);
|
|
2357
2428
|
const thr = { timeoutObject, clear, count: 0 };
|
|
2358
|
-
action.set(
|
|
2429
|
+
action.set(path10, thr);
|
|
2359
2430
|
return thr;
|
|
2360
2431
|
}
|
|
2361
2432
|
_incrReadyCount() {
|
|
@@ -2369,44 +2440,44 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2369
2440
|
* @param event
|
|
2370
2441
|
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
2371
2442
|
*/
|
|
2372
|
-
_awaitWriteFinish(
|
|
2443
|
+
_awaitWriteFinish(path10, threshold, event, awfEmit) {
|
|
2373
2444
|
const awf = this.options.awaitWriteFinish;
|
|
2374
2445
|
if (typeof awf !== "object")
|
|
2375
2446
|
return;
|
|
2376
2447
|
const pollInterval = awf.pollInterval;
|
|
2377
2448
|
let timeoutHandler;
|
|
2378
|
-
let fullPath =
|
|
2379
|
-
if (this.options.cwd && !sp2.isAbsolute(
|
|
2380
|
-
fullPath = sp2.join(this.options.cwd,
|
|
2449
|
+
let fullPath = path10;
|
|
2450
|
+
if (this.options.cwd && !sp2.isAbsolute(path10)) {
|
|
2451
|
+
fullPath = sp2.join(this.options.cwd, path10);
|
|
2381
2452
|
}
|
|
2382
2453
|
const now = /* @__PURE__ */ new Date();
|
|
2383
2454
|
const writes = this._pendingWrites;
|
|
2384
2455
|
function awaitWriteFinishFn(prevStat) {
|
|
2385
2456
|
statcb(fullPath, (err, curStat) => {
|
|
2386
|
-
if (err || !writes.has(
|
|
2457
|
+
if (err || !writes.has(path10)) {
|
|
2387
2458
|
if (err && err.code !== "ENOENT")
|
|
2388
2459
|
awfEmit(err);
|
|
2389
2460
|
return;
|
|
2390
2461
|
}
|
|
2391
2462
|
const now2 = Number(/* @__PURE__ */ new Date());
|
|
2392
2463
|
if (prevStat && curStat.size !== prevStat.size) {
|
|
2393
|
-
writes.get(
|
|
2464
|
+
writes.get(path10).lastChange = now2;
|
|
2394
2465
|
}
|
|
2395
|
-
const pw = writes.get(
|
|
2466
|
+
const pw = writes.get(path10);
|
|
2396
2467
|
const df = now2 - pw.lastChange;
|
|
2397
2468
|
if (df >= threshold) {
|
|
2398
|
-
writes.delete(
|
|
2469
|
+
writes.delete(path10);
|
|
2399
2470
|
awfEmit(void 0, curStat);
|
|
2400
2471
|
} else {
|
|
2401
2472
|
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
2402
2473
|
}
|
|
2403
2474
|
});
|
|
2404
2475
|
}
|
|
2405
|
-
if (!writes.has(
|
|
2406
|
-
writes.set(
|
|
2476
|
+
if (!writes.has(path10)) {
|
|
2477
|
+
writes.set(path10, {
|
|
2407
2478
|
lastChange: now,
|
|
2408
2479
|
cancelWait: () => {
|
|
2409
|
-
writes.delete(
|
|
2480
|
+
writes.delete(path10);
|
|
2410
2481
|
clearTimeout(timeoutHandler);
|
|
2411
2482
|
return event;
|
|
2412
2483
|
}
|
|
@@ -2417,8 +2488,8 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2417
2488
|
/**
|
|
2418
2489
|
* Determines whether user has asked to ignore this path.
|
|
2419
2490
|
*/
|
|
2420
|
-
_isIgnored(
|
|
2421
|
-
if (this.options.atomic && DOT_RE.test(
|
|
2491
|
+
_isIgnored(path10, stats) {
|
|
2492
|
+
if (this.options.atomic && DOT_RE.test(path10))
|
|
2422
2493
|
return true;
|
|
2423
2494
|
if (!this._userIgnored) {
|
|
2424
2495
|
const { cwd } = this.options;
|
|
@@ -2428,17 +2499,17 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2428
2499
|
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
2429
2500
|
this._userIgnored = anymatch(list, void 0);
|
|
2430
2501
|
}
|
|
2431
|
-
return this._userIgnored(
|
|
2502
|
+
return this._userIgnored(path10, stats);
|
|
2432
2503
|
}
|
|
2433
|
-
_isntIgnored(
|
|
2434
|
-
return !this._isIgnored(
|
|
2504
|
+
_isntIgnored(path10, stat9) {
|
|
2505
|
+
return !this._isIgnored(path10, stat9);
|
|
2435
2506
|
}
|
|
2436
2507
|
/**
|
|
2437
2508
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
2438
2509
|
* @param path file or directory pattern being watched
|
|
2439
2510
|
*/
|
|
2440
|
-
_getWatchHelpers(
|
|
2441
|
-
return new WatchHelper(
|
|
2511
|
+
_getWatchHelpers(path10) {
|
|
2512
|
+
return new WatchHelper(path10, this.options.followSymlinks, this);
|
|
2442
2513
|
}
|
|
2443
2514
|
// Directory helpers
|
|
2444
2515
|
// -----------------
|
|
@@ -2470,63 +2541,63 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2470
2541
|
* @param item base path of item/directory
|
|
2471
2542
|
*/
|
|
2472
2543
|
_remove(directory, item, isDirectory) {
|
|
2473
|
-
const
|
|
2474
|
-
const fullPath = sp2.resolve(
|
|
2475
|
-
isDirectory = isDirectory != null ? isDirectory : this._watched.has(
|
|
2476
|
-
if (!this._throttle("remove",
|
|
2544
|
+
const path10 = sp2.join(directory, item);
|
|
2545
|
+
const fullPath = sp2.resolve(path10);
|
|
2546
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path10) || this._watched.has(fullPath);
|
|
2547
|
+
if (!this._throttle("remove", path10, 100))
|
|
2477
2548
|
return;
|
|
2478
2549
|
if (!isDirectory && this._watched.size === 1) {
|
|
2479
2550
|
this.add(directory, item, true);
|
|
2480
2551
|
}
|
|
2481
|
-
const wp = this._getWatchedDir(
|
|
2552
|
+
const wp = this._getWatchedDir(path10);
|
|
2482
2553
|
const nestedDirectoryChildren = wp.getChildren();
|
|
2483
|
-
nestedDirectoryChildren.forEach((nested) => this._remove(
|
|
2554
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path10, nested));
|
|
2484
2555
|
const parent = this._getWatchedDir(directory);
|
|
2485
2556
|
const wasTracked = parent.has(item);
|
|
2486
2557
|
parent.remove(item);
|
|
2487
2558
|
if (this._symlinkPaths.has(fullPath)) {
|
|
2488
2559
|
this._symlinkPaths.delete(fullPath);
|
|
2489
2560
|
}
|
|
2490
|
-
let relPath =
|
|
2561
|
+
let relPath = path10;
|
|
2491
2562
|
if (this.options.cwd)
|
|
2492
|
-
relPath = sp2.relative(this.options.cwd,
|
|
2563
|
+
relPath = sp2.relative(this.options.cwd, path10);
|
|
2493
2564
|
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
2494
2565
|
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
2495
2566
|
if (event === EVENTS.ADD)
|
|
2496
2567
|
return;
|
|
2497
2568
|
}
|
|
2498
|
-
this._watched.delete(
|
|
2569
|
+
this._watched.delete(path10);
|
|
2499
2570
|
this._watched.delete(fullPath);
|
|
2500
2571
|
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
2501
|
-
if (wasTracked && !this._isIgnored(
|
|
2502
|
-
this._emit(eventName,
|
|
2503
|
-
this._closePath(
|
|
2572
|
+
if (wasTracked && !this._isIgnored(path10))
|
|
2573
|
+
this._emit(eventName, path10);
|
|
2574
|
+
this._closePath(path10);
|
|
2504
2575
|
}
|
|
2505
2576
|
/**
|
|
2506
2577
|
* Closes all watchers for a path
|
|
2507
2578
|
*/
|
|
2508
|
-
_closePath(
|
|
2509
|
-
this._closeFile(
|
|
2510
|
-
const dir = sp2.dirname(
|
|
2511
|
-
this._getWatchedDir(dir).remove(sp2.basename(
|
|
2579
|
+
_closePath(path10) {
|
|
2580
|
+
this._closeFile(path10);
|
|
2581
|
+
const dir = sp2.dirname(path10);
|
|
2582
|
+
this._getWatchedDir(dir).remove(sp2.basename(path10));
|
|
2512
2583
|
}
|
|
2513
2584
|
/**
|
|
2514
2585
|
* Closes only file-specific watchers
|
|
2515
2586
|
*/
|
|
2516
|
-
_closeFile(
|
|
2517
|
-
const closers = this._closers.get(
|
|
2587
|
+
_closeFile(path10) {
|
|
2588
|
+
const closers = this._closers.get(path10);
|
|
2518
2589
|
if (!closers)
|
|
2519
2590
|
return;
|
|
2520
2591
|
closers.forEach((closer) => closer());
|
|
2521
|
-
this._closers.delete(
|
|
2592
|
+
this._closers.delete(path10);
|
|
2522
2593
|
}
|
|
2523
|
-
_addPathCloser(
|
|
2594
|
+
_addPathCloser(path10, closer) {
|
|
2524
2595
|
if (!closer)
|
|
2525
2596
|
return;
|
|
2526
|
-
let list = this._closers.get(
|
|
2597
|
+
let list = this._closers.get(path10);
|
|
2527
2598
|
if (!list) {
|
|
2528
2599
|
list = [];
|
|
2529
|
-
this._closers.set(
|
|
2600
|
+
this._closers.set(path10, list);
|
|
2530
2601
|
}
|
|
2531
2602
|
list.push(closer);
|
|
2532
2603
|
}
|
|
@@ -2557,49 +2628,227 @@ var chokidar_default = { watch, FSWatcher };
|
|
|
2557
2628
|
|
|
2558
2629
|
// src/core/watch.ts
|
|
2559
2630
|
import { $ as $7 } from "execa";
|
|
2631
|
+
import { build as esbuild2 } from "esbuild";
|
|
2632
|
+
import { findWorkspacesRoot as findWorkspacesRoot2 } from "find-workspaces";
|
|
2560
2633
|
var watchCommand = new Command10("watch").description(
|
|
2561
|
-
"Watches the src directory and rebuilds
|
|
2562
|
-
).action(() => {
|
|
2634
|
+
"Watches the src directory and incrementally rebuilds files on changes (Vite-style)"
|
|
2635
|
+
).action(async () => {
|
|
2563
2636
|
const cwd = process.cwd();
|
|
2564
|
-
const srcDir =
|
|
2565
|
-
|
|
2566
|
-
let
|
|
2567
|
-
let
|
|
2568
|
-
const
|
|
2569
|
-
if (
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
\
|
|
2637
|
+
const srcDir = path9.join(cwd, "src");
|
|
2638
|
+
const pkgJsonPath = path9.join(cwd, "package.json");
|
|
2639
|
+
let watcher = null;
|
|
2640
|
+
let configWatcher = null;
|
|
2641
|
+
const startWatcher = async (isReload = false) => {
|
|
2642
|
+
if (watcher) {
|
|
2643
|
+
await watcher.close();
|
|
2644
|
+
}
|
|
2645
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
2646
|
+
if (isReload) {
|
|
2647
|
+
console.log(`
|
|
2648
|
+
\u{1F504} Configuration change detected. Reloading...`);
|
|
2649
|
+
}
|
|
2650
|
+
const packageJsonContent = await fs9.readFile(pkgJsonPath, "utf8");
|
|
2651
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
2652
|
+
const buildDirBase = packageJson.publishConfig?.directory || "build";
|
|
2653
|
+
const buildDir = path9.join(cwd, buildDirBase);
|
|
2654
|
+
const fileConfig = await loadConfig();
|
|
2655
|
+
const bundles = fileConfig.bundle || ["esm", "cjs"];
|
|
2656
|
+
const isFlat = fileConfig.flat ?? false;
|
|
2657
|
+
const packageType = packageJson.type === "module" ? "module" : "commonjs";
|
|
2658
|
+
const isEsbuild = !!fileConfig.esbuild;
|
|
2659
|
+
const builder = isEsbuild ? "esbuild" : "babel";
|
|
2660
|
+
const workspaceDir = await findWorkspacesRoot2(cwd);
|
|
2661
|
+
const rootDir = workspaceDir ? workspaceDir.location : cwd;
|
|
2662
|
+
const pm = getPackageManager();
|
|
2663
|
+
const pmExec = getPmExec();
|
|
2664
|
+
let babelRuntimeVersion = packageJson.dependencies?.["@babel/runtime"];
|
|
2665
|
+
const reactVersion = packageJson.peerDependencies?.react || "latest";
|
|
2666
|
+
console.log(`\u{1F440} Watching for changes (Builder: ${builder})...`);
|
|
2576
2667
|
try {
|
|
2577
|
-
await $7({
|
|
2578
|
-
|
|
2668
|
+
await $7({
|
|
2669
|
+
stdio: "inherit",
|
|
2670
|
+
preferLocal: true
|
|
2671
|
+
})`${pmExec} sse-tools build`;
|
|
2579
2672
|
} catch (err) {
|
|
2580
|
-
console.error(`\u274C
|
|
2581
|
-
|
|
2582
|
-
isBuilding = false;
|
|
2583
|
-
if (buildQueued) {
|
|
2584
|
-
buildQueued = false;
|
|
2585
|
-
runBuild();
|
|
2586
|
-
}
|
|
2673
|
+
console.error(`\u274C Initial build failed. Waiting for changes...
|
|
2674
|
+
`);
|
|
2587
2675
|
}
|
|
2676
|
+
const buildFile = async (filePath) => {
|
|
2677
|
+
const relativePath = path9.relative(srcDir, filePath);
|
|
2678
|
+
if (builder === "esbuild") {
|
|
2679
|
+
if (isVerbose)
|
|
2680
|
+
console.log(
|
|
2681
|
+
`\u{1F680} [esbuild] Incremental rebuild triggered by ${relativePath}...`
|
|
2682
|
+
);
|
|
2683
|
+
const esbuildConfig = fileConfig.esbuild;
|
|
2684
|
+
const entryPoints = typeof esbuildConfig.entry === "string" ? [esbuildConfig.entry] : esbuildConfig.entry;
|
|
2685
|
+
try {
|
|
2686
|
+
await Promise.all(
|
|
2687
|
+
bundles.map(async (bundle) => {
|
|
2688
|
+
const outExtension = getOutExtension(bundle, {
|
|
2689
|
+
isFlat,
|
|
2690
|
+
packageType
|
|
2691
|
+
});
|
|
2692
|
+
const relativeOutDir = isFlat ? "." : bundle === "esm" ? "esm" : ".";
|
|
2693
|
+
const outputDir = path9.join(buildDir, relativeOutDir);
|
|
2694
|
+
await esbuild2({
|
|
2695
|
+
entryPoints,
|
|
2696
|
+
bundle: true,
|
|
2697
|
+
outdir: outputDir,
|
|
2698
|
+
format: bundle === "esm" ? "esm" : "cjs",
|
|
2699
|
+
target: esbuildConfig.target || ["es2020", "node14"],
|
|
2700
|
+
minify: esbuildConfig.minify ?? false,
|
|
2701
|
+
outExtension: { ".js": outExtension },
|
|
2702
|
+
external: [
|
|
2703
|
+
...Object.keys(packageJson.dependencies || {}),
|
|
2704
|
+
...Object.keys(packageJson.peerDependencies || {}),
|
|
2705
|
+
...esbuildConfig.external || []
|
|
2706
|
+
]
|
|
2707
|
+
});
|
|
2708
|
+
})
|
|
2709
|
+
);
|
|
2710
|
+
if (isVerbose) console.log(`\u2705 [esbuild] Rebuild complete.`);
|
|
2711
|
+
} catch (err) {
|
|
2712
|
+
console.error(`\u274C [esbuild] Rebuild failed:`, err.message);
|
|
2713
|
+
}
|
|
2714
|
+
} else {
|
|
2715
|
+
const ext = path9.extname(filePath);
|
|
2716
|
+
if (![".js", ".jsx", ".ts", ".tsx"].includes(ext) || filePath.endsWith(".d.ts"))
|
|
2717
|
+
return;
|
|
2718
|
+
let babelConfigFile = path9.join(rootDir, "babel.config.js");
|
|
2719
|
+
if (!await fs9.stat(babelConfigFile).then(() => true).catch(() => false)) {
|
|
2720
|
+
babelConfigFile = path9.join(rootDir, "babel.config.mjs");
|
|
2721
|
+
}
|
|
2722
|
+
await Promise.all(
|
|
2723
|
+
bundles.map(async (bundle) => {
|
|
2724
|
+
const outExtension = getOutExtension(bundle, {
|
|
2725
|
+
isFlat,
|
|
2726
|
+
packageType
|
|
2727
|
+
});
|
|
2728
|
+
const relativeOutDir = isFlat ? "." : bundle === "esm" ? "esm" : ".";
|
|
2729
|
+
const outputDir = path9.join(buildDir, relativeOutDir);
|
|
2730
|
+
const outFilePath = path9.join(
|
|
2731
|
+
outputDir,
|
|
2732
|
+
relativePath.replace(new RegExp(`\\${ext}$`), outExtension)
|
|
2733
|
+
);
|
|
2734
|
+
await fs9.mkdir(path9.dirname(outFilePath), { recursive: true });
|
|
2735
|
+
const env = {
|
|
2736
|
+
NODE_ENV: "production",
|
|
2737
|
+
BABEL_ENV: bundle === "esm" ? "stable" : "node",
|
|
2738
|
+
SSE_OUT_FILE_EXTENSION: outExtension,
|
|
2739
|
+
SSE_BABEL_RUNTIME_VERSION: babelRuntimeVersion,
|
|
2740
|
+
...getVersionEnvVariables(packageJson.version)
|
|
2741
|
+
};
|
|
2742
|
+
await $7({
|
|
2743
|
+
stdio: "pipe",
|
|
2744
|
+
preferLocal: true,
|
|
2745
|
+
env: { ...process.env, ...env }
|
|
2746
|
+
})`babel --config-file ${babelConfigFile} --extensions .js,.jsx,.ts,.tsx ${filePath} --out-file ${outFilePath}`;
|
|
2747
|
+
})
|
|
2748
|
+
);
|
|
2749
|
+
if (isVerbose) console.log(`\u2705 [babel] Updated ${relativePath}`);
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2752
|
+
const updateExports = async () => {
|
|
2753
|
+
try {
|
|
2754
|
+
const freshPkg = JSON.parse(
|
|
2755
|
+
await fs9.readFile(pkgJsonPath, "utf8")
|
|
2756
|
+
);
|
|
2757
|
+
const relativeOutDirs = !isFlat ? { cjs: ".", esm: "esm" } : { cjs: ".", esm: "." };
|
|
2758
|
+
await writePackageJson({
|
|
2759
|
+
cwd,
|
|
2760
|
+
packageJson: freshPkg,
|
|
2761
|
+
bundles: bundles.map((type) => ({
|
|
2762
|
+
type,
|
|
2763
|
+
dir: relativeOutDirs[type]
|
|
2764
|
+
})),
|
|
2765
|
+
outputDir: buildDir,
|
|
2766
|
+
addTypes: fileConfig.buildTypes ?? true,
|
|
2767
|
+
isFlat,
|
|
2768
|
+
packageType,
|
|
2769
|
+
exportExtensions: fileConfig.exportExtensions
|
|
2770
|
+
});
|
|
2771
|
+
} catch (e) {
|
|
2772
|
+
console.error(`\u274C Failed to update exports: ${e.message}`);
|
|
2773
|
+
}
|
|
2774
|
+
};
|
|
2775
|
+
let exportTimeout;
|
|
2776
|
+
const debouncedUpdateExports = () => {
|
|
2777
|
+
clearTimeout(exportTimeout);
|
|
2778
|
+
exportTimeout = setTimeout(() => updateExports(), 150);
|
|
2779
|
+
};
|
|
2780
|
+
watcher = chokidar_default.watch(srcDir, {
|
|
2781
|
+
ignored: /(^|[\/\\])\../,
|
|
2782
|
+
persistent: true,
|
|
2783
|
+
ignoreInitial: true
|
|
2784
|
+
});
|
|
2785
|
+
watcher.on("change", async (filePath) => await buildFile(filePath)).on("add", async (filePath) => {
|
|
2786
|
+
await buildFile(filePath);
|
|
2787
|
+
debouncedUpdateExports();
|
|
2788
|
+
}).on("unlink", async (filePath) => {
|
|
2789
|
+
const relativePath = path9.relative(srcDir, filePath);
|
|
2790
|
+
const ext = path9.extname(filePath);
|
|
2791
|
+
for (const bundle of bundles) {
|
|
2792
|
+
const outExtension = getOutExtension(bundle, {
|
|
2793
|
+
isFlat,
|
|
2794
|
+
packageType,
|
|
2795
|
+
isType: false
|
|
2796
|
+
});
|
|
2797
|
+
const relativeOutDir = isFlat ? "." : bundle === "esm" ? "esm" : ".";
|
|
2798
|
+
const outputDir = path9.join(buildDir, relativeOutDir);
|
|
2799
|
+
const outRelativePath = relativePath.replace(
|
|
2800
|
+
new RegExp(`\\${ext}$`),
|
|
2801
|
+
outExtension
|
|
2802
|
+
);
|
|
2803
|
+
await fs9.rm(path9.join(outputDir, outRelativePath), { force: true }).catch(() => {
|
|
2804
|
+
});
|
|
2805
|
+
}
|
|
2806
|
+
debouncedUpdateExports();
|
|
2807
|
+
}).on("unlinkDir", async (dirPath) => {
|
|
2808
|
+
const relativePath = path9.relative(srcDir, dirPath);
|
|
2809
|
+
for (const bundle of bundles) {
|
|
2810
|
+
const relativeOutDir = isFlat ? "." : bundle === "esm" ? "esm" : ".";
|
|
2811
|
+
await fs9.rm(path9.join(buildDir, relativeOutDir, relativePath), {
|
|
2812
|
+
recursive: true,
|
|
2813
|
+
force: true
|
|
2814
|
+
}).catch(() => {
|
|
2815
|
+
});
|
|
2816
|
+
}
|
|
2817
|
+
debouncedUpdateExports();
|
|
2818
|
+
});
|
|
2588
2819
|
};
|
|
2589
|
-
const
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2820
|
+
const configFiles = [
|
|
2821
|
+
"sse.config.ts",
|
|
2822
|
+
"sse.config.js",
|
|
2823
|
+
"sse.config.mjs",
|
|
2824
|
+
"sse.config.cjs",
|
|
2825
|
+
"sse.config.mts",
|
|
2826
|
+
"sse.config.cts",
|
|
2827
|
+
"sse.config.json",
|
|
2828
|
+
"package.json"
|
|
2829
|
+
];
|
|
2830
|
+
configWatcher = chokidar_default.watch(
|
|
2831
|
+
configFiles.map((f) => path9.join(cwd, f)),
|
|
2832
|
+
{
|
|
2833
|
+
persistent: true,
|
|
2834
|
+
ignoreInitial: true
|
|
2835
|
+
}
|
|
2836
|
+
);
|
|
2837
|
+
configWatcher.on("change", () => startWatcher(true));
|
|
2838
|
+
await startWatcher();
|
|
2597
2839
|
});
|
|
2598
2840
|
|
|
2599
2841
|
// src/cli.ts
|
|
2600
2842
|
async function main() {
|
|
2601
2843
|
const program = new Command11();
|
|
2602
|
-
program.name("sse-tools").description(
|
|
2844
|
+
program.name("sse-tools").description(
|
|
2845
|
+
chalk2.cyan("CLI utilities for managing and building SSE packages")
|
|
2846
|
+
).version("1.0.0").option("-v, --verbose", "Enable verbose logging across all commands");
|
|
2847
|
+
program.hook("preAction", (thisCommand) => {
|
|
2848
|
+
if (thisCommand.opts().verbose) {
|
|
2849
|
+
process.env.SSE_BUILD_VERBOSE = "true";
|
|
2850
|
+
}
|
|
2851
|
+
});
|
|
2603
2852
|
program.addCommand(buildCommand);
|
|
2604
2853
|
program.addCommand(publishCommand);
|
|
2605
2854
|
program.addCommand(cleanCommand);
|