@sse-ui/builder 1.1.0 → 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-44E7L73Q.js → chunk-B6FMAT44.js} +16 -8
- package/dist/{babel-QBNMMXUJ.js → chunk-MBPIJFGX.js} +21 -18
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/cli.js +601 -326
- package/dist/config.d.ts +48 -36
- 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 +16 -5
- package/dist/typescript-3J237V7Q.js +0 -217
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
getVersionEnvVariables
|
|
4
|
+
} from "./chunk-MBPIJFGX.js";
|
|
2
5
|
import {
|
|
3
6
|
addLicense,
|
|
4
7
|
getOutExtension,
|
|
5
8
|
mapConcurrently,
|
|
6
9
|
validatePkgJson,
|
|
7
10
|
writePackageJson
|
|
8
|
-
} from "./chunk-
|
|
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
|
|
@@ -20,6 +25,7 @@ import { sep as posixSep } from "path/posix";
|
|
|
20
25
|
import * as semver from "semver";
|
|
21
26
|
import { Command } from "commander";
|
|
22
27
|
import { build as esbuild } from "esbuild";
|
|
28
|
+
import chalk from "chalk";
|
|
23
29
|
|
|
24
30
|
// src/utils/loadConfig.ts
|
|
25
31
|
import { loadConfig as loadC12Config } from "c12";
|
|
@@ -30,7 +36,7 @@ async function loadConfig() {
|
|
|
30
36
|
rcFile: false,
|
|
31
37
|
globalRc: false
|
|
32
38
|
});
|
|
33
|
-
if (configFile) {
|
|
39
|
+
if (configFile && (config?.verbose || process.env.SSE_BUILD_VERBOSE === "true")) {
|
|
34
40
|
console.log(`\u{1F4DD} Loaded config from ${configFile}`);
|
|
35
41
|
}
|
|
36
42
|
return config || {};
|
|
@@ -41,8 +47,22 @@ async function loadConfig() {
|
|
|
41
47
|
}
|
|
42
48
|
}
|
|
43
49
|
|
|
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";
|
|
56
|
+
}
|
|
57
|
+
function getPmExec() {
|
|
58
|
+
const pm = getPackageManager();
|
|
59
|
+
if (pm === "pnpm") return ["pnpm", "exec"];
|
|
60
|
+
if (pm === "yarn") return ["yarn"];
|
|
61
|
+
return ["npx"];
|
|
62
|
+
}
|
|
63
|
+
|
|
44
64
|
// src/core/build.ts
|
|
45
|
-
var buildCommand = new Command("build").description("Builds the package for publishing.").option("--bundle <bundles...>", "Bundles to output", ["esm", "cjs"]).option(
|
|
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(
|
|
46
66
|
"--hasLargeFiles",
|
|
47
67
|
"Set to `true` if you know you are transpiling large files.",
|
|
48
68
|
false
|
|
@@ -72,79 +92,76 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
72
92
|
[]
|
|
73
93
|
).option("--enableReactCompiler", "Whether to use the React compiler.", false).option(
|
|
74
94
|
"--tsgo",
|
|
75
|
-
|
|
95
|
+
"Uses tsgo cli instead of tsc for type generation.",
|
|
76
96
|
process.env.SSE_USE_TSGO === "1" || process.env.SSE_USE_TSGO === "true"
|
|
77
97
|
).option(
|
|
78
98
|
"--flat",
|
|
79
99
|
"Builds the package in a flat structure without subdirectories for each module type.",
|
|
80
100
|
process.env.SSE_BUILD_FLAT === "1"
|
|
81
|
-
).option(
|
|
82
|
-
"--bundleSingleFile",
|
|
83
|
-
"Bundle all modules into single files using esbuild (tsup style)",
|
|
84
|
-
false
|
|
85
101
|
).option(
|
|
86
102
|
"--exportExtensions <exts...>",
|
|
87
103
|
"Available extensions for generating exports wildcards.",
|
|
88
104
|
[".js", ".mjs", ".cjs"]
|
|
89
|
-
).
|
|
105
|
+
).action(async (cliOptions) => {
|
|
90
106
|
const fileConfig = await loadConfig();
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
bundleSingleFile: cliOptions.bundleSingleFile ?? fileConfig.bundleSingleFile ?? false,
|
|
107
|
-
exportExtensions: cliOptions.exportExtensions ?? fileConfig.exportExtensions ?? [".js", ".mjs", ".cjs"]
|
|
108
|
-
};
|
|
109
|
-
const {
|
|
110
|
-
bundle: bundles,
|
|
111
|
-
hasLargeFiles,
|
|
112
|
-
skipBundlePackageJson,
|
|
113
|
-
verbose = false,
|
|
114
|
-
ignore: extraIgnores,
|
|
115
|
-
buildTypes,
|
|
116
|
-
skipTsc,
|
|
117
|
-
skipBabelRuntimeCheck = false,
|
|
118
|
-
skipPackageJson = false,
|
|
119
|
-
enableReactCompiler = false,
|
|
120
|
-
tsgo: useTsgo = false,
|
|
121
|
-
bundleSingleFile,
|
|
122
|
-
exportExtensions
|
|
123
|
-
} = 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 || []];
|
|
124
122
|
const cwd = process.cwd();
|
|
125
123
|
const pkgJsonPath = path.join(cwd, "package.json");
|
|
126
124
|
const packageJson = JSON.parse(
|
|
127
125
|
await fs.readFile(pkgJsonPath, { encoding: "utf8" })
|
|
128
126
|
);
|
|
129
127
|
validatePkgJson(packageJson, {
|
|
130
|
-
skipMainCheck:
|
|
128
|
+
skipMainCheck: cliOptions.skipMainCheck,
|
|
131
129
|
enableReactCompiler
|
|
132
130
|
});
|
|
133
131
|
const buildDirBase = packageJson.publishConfig?.directory;
|
|
134
132
|
const buildDir = path.join(cwd, buildDirBase);
|
|
135
133
|
const packageType = packageJson.type === "module" ? "module" : "commonjs";
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
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.");
|
|
139
137
|
}
|
|
140
138
|
await fs.rm(buildDir, { recursive: true, force: true });
|
|
139
|
+
const pm = getPackageManager();
|
|
141
140
|
let babelRuntimeVersion = packageJson.dependencies?.["@babel/runtime"];
|
|
142
141
|
if (babelRuntimeVersion === "catalog:") {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
+
}
|
|
146
163
|
}
|
|
147
|
-
if (!babelRuntimeVersion && !skipBabelRuntimeCheck) {
|
|
164
|
+
if (builder === "babel" && !babelRuntimeVersion && !skipBabelRuntimeCheck) {
|
|
148
165
|
throw new Error(
|
|
149
166
|
"package.json needs to have a dependency on `@babel/runtime` when building with `@babel/plugin-transform-runtime`."
|
|
150
167
|
);
|
|
@@ -155,29 +172,30 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
155
172
|
);
|
|
156
173
|
return;
|
|
157
174
|
}
|
|
158
|
-
const {
|
|
159
|
-
const relativeOutDirs = !options.flat ? {
|
|
160
|
-
cjs: ".",
|
|
161
|
-
esm: "esm"
|
|
162
|
-
} : {
|
|
163
|
-
cjs: ".",
|
|
164
|
-
esm: "."
|
|
165
|
-
};
|
|
175
|
+
const relativeOutDirs = !isFlat ? { cjs: ".", esm: "esm" } : { cjs: ".", esm: "." };
|
|
166
176
|
const sourceDir = path.join(cwd, "src");
|
|
167
177
|
const reactVersion = semver.minVersion(packageJson.peerDependencies?.react || "")?.version ?? "latest";
|
|
168
|
-
if (enableReactCompiler) {
|
|
178
|
+
if (enableReactCompiler && isVerbose) {
|
|
169
179
|
const mode = process.env.SSE_REACT_COMPILER_MODE ?? "opt-in";
|
|
170
180
|
console.log(
|
|
171
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.' : ""}`
|
|
172
182
|
);
|
|
173
183
|
}
|
|
174
|
-
if (
|
|
175
|
-
if (
|
|
184
|
+
if (builder === "esbuild") {
|
|
185
|
+
if (isVerbose)
|
|
176
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."
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
const entryPoints = typeof rawEntryPoints === "string" ? [rawEntryPoints] : rawEntryPoints;
|
|
177
195
|
await Promise.all(
|
|
178
196
|
bundles.map(async (bundle) => {
|
|
179
197
|
const outExtension = getOutExtension(bundle, {
|
|
180
|
-
isFlat: !!
|
|
198
|
+
isFlat: !!isFlat,
|
|
181
199
|
isType: false,
|
|
182
200
|
packageType
|
|
183
201
|
});
|
|
@@ -185,18 +203,21 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
185
203
|
const outputDir = path.join(buildDir, relativeOutDir);
|
|
186
204
|
await fs.mkdir(outputDir, { recursive: true });
|
|
187
205
|
await esbuild({
|
|
188
|
-
entryPoints
|
|
206
|
+
entryPoints,
|
|
189
207
|
bundle: true,
|
|
190
|
-
|
|
208
|
+
outdir: outputDir,
|
|
191
209
|
format: bundle === "esm" ? "esm" : "cjs",
|
|
192
|
-
target: ["es2020", "node14"],
|
|
193
|
-
minify: false,
|
|
210
|
+
target: esbuildConfig.target || ["es2020", "node14"],
|
|
211
|
+
minify: esbuildConfig.minify ?? false,
|
|
212
|
+
outExtension: { ".js": outExtension },
|
|
213
|
+
// Forces the correct extension output
|
|
194
214
|
external: [
|
|
195
215
|
...Object.keys(packageJson.dependencies || {}),
|
|
196
|
-
...Object.keys(packageJson.peerDependencies || {})
|
|
216
|
+
...Object.keys(packageJson.peerDependencies || {}),
|
|
217
|
+
...esbuildConfig.external || []
|
|
197
218
|
]
|
|
198
219
|
});
|
|
199
|
-
if (buildDir !== outputDir && !skipBundlePackageJson && !
|
|
220
|
+
if (buildDir !== outputDir && !skipBundlePackageJson && !isFlat) {
|
|
200
221
|
await fs.writeFile(
|
|
201
222
|
path.join(outputDir, "package.json"),
|
|
202
223
|
JSON.stringify({
|
|
@@ -211,16 +232,23 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
211
232
|
name: packageJson.name,
|
|
212
233
|
version: packageJson.version,
|
|
213
234
|
outputDir,
|
|
214
|
-
isFlat: !!
|
|
235
|
+
isFlat: !!isFlat,
|
|
215
236
|
packageType
|
|
216
237
|
});
|
|
217
238
|
})
|
|
218
239
|
);
|
|
219
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
|
+
];
|
|
220
248
|
await Promise.all(
|
|
221
249
|
bundles.map(async (bundle) => {
|
|
222
250
|
const outExtension = getOutExtension(bundle, {
|
|
223
|
-
isFlat: !!
|
|
251
|
+
isFlat: !!isFlat,
|
|
224
252
|
isType: false,
|
|
225
253
|
packageType
|
|
226
254
|
});
|
|
@@ -236,18 +264,16 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
236
264
|
babelRuntimeVersion,
|
|
237
265
|
hasLargeFiles,
|
|
238
266
|
bundle,
|
|
239
|
-
verbose,
|
|
267
|
+
verbose: isVerbose,
|
|
240
268
|
optimizeClsx: packageJson.dependencies?.clsx !== void 0 || packageJson.dependencies?.classnames !== void 0,
|
|
241
269
|
removePropTypes: packageJson.dependencies?.["prop-types"] !== void 0,
|
|
242
270
|
pkgVersion: packageJson.version,
|
|
243
271
|
ignores: extraIgnores,
|
|
244
272
|
outExtension,
|
|
245
|
-
reactCompiler: enableReactCompiler ? {
|
|
246
|
-
reactVersion: reactVersion || "latest"
|
|
247
|
-
} : void 0
|
|
273
|
+
reactCompiler: enableReactCompiler ? { reactVersion: reactVersion || "latest" } : void 0
|
|
248
274
|
})
|
|
249
275
|
);
|
|
250
|
-
if (buildDir !== outputDir && !skipBundlePackageJson && !
|
|
276
|
+
if (buildDir !== outputDir && !skipBundlePackageJson && !isFlat) {
|
|
251
277
|
promises.push(
|
|
252
278
|
fs.writeFile(
|
|
253
279
|
path.join(outputDir, "package.json"),
|
|
@@ -258,7 +284,7 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
258
284
|
)
|
|
259
285
|
);
|
|
260
286
|
}
|
|
261
|
-
if (!
|
|
287
|
+
if (!isFlat) {
|
|
262
288
|
promises.push(cjsCopy({ from: sourceDir, to: outputDir }));
|
|
263
289
|
}
|
|
264
290
|
await Promise.all(promises);
|
|
@@ -268,35 +294,47 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
268
294
|
name: packageJson.name,
|
|
269
295
|
version: packageJson.version,
|
|
270
296
|
outputDir,
|
|
271
|
-
isFlat: !!
|
|
297
|
+
isFlat: !!isFlat,
|
|
272
298
|
packageType
|
|
273
299
|
});
|
|
274
300
|
})
|
|
275
301
|
);
|
|
276
|
-
if (
|
|
302
|
+
if (isFlat) {
|
|
277
303
|
await cjsCopy({ from: sourceDir, to: buildDir });
|
|
278
304
|
}
|
|
279
305
|
}
|
|
280
|
-
if (buildTypes) {
|
|
281
|
-
|
|
306
|
+
if (buildTypes === true) {
|
|
307
|
+
if (isVerbose) console.log("\u{1F4DD} Generating TypeScript declarations...");
|
|
308
|
+
const tsMod = await import("./typescript-6QWCIZ3Q.js");
|
|
282
309
|
const bundleMap = bundles.map((type) => ({
|
|
283
310
|
type,
|
|
284
311
|
dir: relativeOutDirs[type]
|
|
285
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
|
+
}
|
|
286
319
|
await tsMod.createTypes({
|
|
287
320
|
bundles: bundleMap,
|
|
288
321
|
srcDir: sourceDir,
|
|
289
322
|
cwd,
|
|
290
323
|
skipTsc,
|
|
291
|
-
isFlat: !!
|
|
324
|
+
isFlat: !!isFlat,
|
|
292
325
|
buildDir,
|
|
293
326
|
useTsgo,
|
|
294
327
|
packageType,
|
|
295
|
-
verbose:
|
|
328
|
+
verbose: isVerbose,
|
|
329
|
+
builder,
|
|
330
|
+
entryPoints: esbuildEntryPoints
|
|
296
331
|
});
|
|
297
332
|
}
|
|
298
333
|
if (skipPackageJson) {
|
|
299
|
-
|
|
334
|
+
if (isVerbose)
|
|
335
|
+
console.log(
|
|
336
|
+
"Skipping package.json generation in the output directory."
|
|
337
|
+
);
|
|
300
338
|
return;
|
|
301
339
|
}
|
|
302
340
|
await writePackageJson({
|
|
@@ -308,15 +346,15 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
308
346
|
})),
|
|
309
347
|
outputDir: buildDir,
|
|
310
348
|
addTypes: buildTypes,
|
|
311
|
-
isFlat: !!
|
|
349
|
+
isFlat: !!isFlat,
|
|
312
350
|
packageType,
|
|
313
|
-
exportExtensions
|
|
351
|
+
exportExtensions
|
|
314
352
|
});
|
|
315
353
|
await copyHandler({
|
|
316
354
|
cwd,
|
|
317
|
-
globs:
|
|
355
|
+
globs: copyGlobs,
|
|
318
356
|
buildDir,
|
|
319
|
-
verbose:
|
|
357
|
+
verbose: isVerbose
|
|
320
358
|
});
|
|
321
359
|
});
|
|
322
360
|
async function copyHandler({
|
|
@@ -340,13 +378,10 @@ async function copyHandler({
|
|
|
340
378
|
await Promise.all(
|
|
341
379
|
localOrRootFiles.map(async (filesToCopy) => {
|
|
342
380
|
for (const file of filesToCopy) {
|
|
343
|
-
if (
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
() => false
|
|
348
|
-
)
|
|
349
|
-
) {
|
|
381
|
+
if (await fs.stat(file).then(
|
|
382
|
+
() => true,
|
|
383
|
+
() => false
|
|
384
|
+
)) {
|
|
350
385
|
defaultFiles.push(file);
|
|
351
386
|
break;
|
|
352
387
|
}
|
|
@@ -411,7 +446,7 @@ async function copyHandler({
|
|
|
411
446
|
},
|
|
412
447
|
20
|
|
413
448
|
);
|
|
414
|
-
console.log(`\u{1F4CB} Copied ${defaultFiles.length} files.`);
|
|
449
|
+
if (verbose) console.log(`\u{1F4CB} Copied ${defaultFiles.length} files.`);
|
|
415
450
|
}
|
|
416
451
|
async function recursiveCopy({
|
|
417
452
|
source,
|
|
@@ -440,12 +475,6 @@ import * as fs2 from "fs/promises";
|
|
|
440
475
|
import * as path2 from "path";
|
|
441
476
|
import { Command as Command2 } from "commander";
|
|
442
477
|
import { $ as $2 } from "execa";
|
|
443
|
-
function getPackageManager() {
|
|
444
|
-
const userAgent = process.env.npm_config_user_agent || "";
|
|
445
|
-
if (userAgent.includes("pnpm")) return "pnpm";
|
|
446
|
-
if (userAgent.includes("yarn")) return "yarn";
|
|
447
|
-
return "npm";
|
|
448
|
-
}
|
|
449
478
|
var publishCommand = new Command2("publish").description(
|
|
450
479
|
"Automatically publishes the built package from the publishConfig.directory"
|
|
451
480
|
).option("--tag <tag>", "Registers the published package with the given tag").option(
|
|
@@ -458,6 +487,7 @@ var publishCommand = new Command2("publish").description(
|
|
|
458
487
|
"--pm <manager>",
|
|
459
488
|
"Force a specific package manager (npm, yarn, pnpm)"
|
|
460
489
|
).action(async (options) => {
|
|
490
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
461
491
|
const cwd = process.cwd();
|
|
462
492
|
const pkgJsonPath = path2.join(cwd, "package.json");
|
|
463
493
|
try {
|
|
@@ -482,9 +512,11 @@ var publishCommand = new Command2("publish").description(
|
|
|
482
512
|
);
|
|
483
513
|
}
|
|
484
514
|
const pm = options.pm || getPackageManager();
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
515
|
+
if (isVerbose) {
|
|
516
|
+
console.log(
|
|
517
|
+
`\u{1F680} Publishing via ${pm.toUpperCase()} from directory: ${publishDirBase}`
|
|
518
|
+
);
|
|
519
|
+
}
|
|
488
520
|
const args = ["publish"];
|
|
489
521
|
if (options.tag) args.push("--tag", options.tag);
|
|
490
522
|
if (options.access) args.push("--access", options.access);
|
|
@@ -513,6 +545,7 @@ import { Command as Command3 } from "commander";
|
|
|
513
545
|
var cleanCommand = new Command3("clean").description(
|
|
514
546
|
"Removes the build directory specified in package.json to start fresh"
|
|
515
547
|
).action(async () => {
|
|
548
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
516
549
|
const cwd = process.cwd();
|
|
517
550
|
const pkgJsonPath = path3.join(cwd, "package.json");
|
|
518
551
|
try {
|
|
@@ -522,7 +555,8 @@ var cleanCommand = new Command3("clean").description(
|
|
|
522
555
|
const packageJson = JSON.parse(packageJsonContent);
|
|
523
556
|
const buildDirBase = packageJson.publishConfig?.directory || "build";
|
|
524
557
|
const buildDir = path3.join(cwd, buildDirBase);
|
|
525
|
-
|
|
558
|
+
if (isVerbose)
|
|
559
|
+
console.log(`\u{1F9F9} Cleaning build directory: ${buildDirBase}...`);
|
|
526
560
|
await fs3.rm(buildDir, { recursive: true, force: true });
|
|
527
561
|
console.log("\u2728 Cleaned successfully!");
|
|
528
562
|
} catch (error) {
|
|
@@ -540,7 +574,8 @@ import { $ as $3 } from "execa";
|
|
|
540
574
|
var typecheckCommand = new Command4("typecheck").description(
|
|
541
575
|
"Runs TypeScript validation across the project without emitting files"
|
|
542
576
|
).option("--watch", "Run typechecking in watch mode").action(async (options) => {
|
|
543
|
-
|
|
577
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
578
|
+
if (isVerbose) console.log("\u{1F50D} Running typecheck...");
|
|
544
579
|
try {
|
|
545
580
|
const args = ["tsc", "--noEmit"];
|
|
546
581
|
if (options.watch) {
|
|
@@ -566,6 +601,8 @@ import { $ as $4 } from "execa";
|
|
|
566
601
|
var packCommand = new Command5("pack").description(
|
|
567
602
|
"Creates a tarball (.tgz) of the built package to inspect before publishing"
|
|
568
603
|
).action(async () => {
|
|
604
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
605
|
+
const pm = getPackageManager();
|
|
569
606
|
const cwd = process.cwd();
|
|
570
607
|
const pkgJsonPath = path4.join(cwd, "package.json");
|
|
571
608
|
try {
|
|
@@ -578,11 +615,12 @@ var packCommand = new Command5("pack").description(
|
|
|
578
615
|
throw new Error(`No publish directory specified in package.json.`);
|
|
579
616
|
}
|
|
580
617
|
const publishDir = path4.join(cwd, publishDirBase);
|
|
581
|
-
|
|
618
|
+
if (isVerbose)
|
|
619
|
+
console.log(`\u{1F4E6} Packing package from directory: ${publishDirBase}...`);
|
|
582
620
|
await $4({
|
|
583
621
|
stdio: "inherit",
|
|
584
622
|
cwd: publishDir
|
|
585
|
-
})
|
|
623
|
+
})`${pm} pack`;
|
|
586
624
|
console.log(
|
|
587
625
|
"\u2705 Pack successful! You can inspect the generated .tgz file."
|
|
588
626
|
);
|
|
@@ -594,12 +632,19 @@ var packCommand = new Command5("pack").description(
|
|
|
594
632
|
});
|
|
595
633
|
|
|
596
634
|
// src/core/version.ts
|
|
635
|
+
import * as fs5 from "fs/promises";
|
|
636
|
+
import * as path5 from "path";
|
|
597
637
|
import { Command as Command6 } from "commander";
|
|
598
638
|
import { $ as $5 } from "execa";
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
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."
|
|
602
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();
|
|
603
648
|
const validTypes = [
|
|
604
649
|
"patch",
|
|
605
650
|
"minor",
|
|
@@ -609,19 +654,64 @@ var versionCommand = new Command6("version").description("Bumps the package vers
|
|
|
609
654
|
"premajor",
|
|
610
655
|
"prerelease"
|
|
611
656
|
];
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
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
|
+
}
|
|
617
706
|
}
|
|
618
|
-
|
|
707
|
+
if (isVerbose)
|
|
708
|
+
console.log(`\u{1F4C8} Bumping version (${selectedType}) via ${pm}...`);
|
|
619
709
|
try {
|
|
620
|
-
const args = ["version",
|
|
710
|
+
const args = ["version", selectedType];
|
|
621
711
|
if (!options.gitTagVersion) {
|
|
622
712
|
args.push("--no-git-tag-version");
|
|
623
713
|
}
|
|
624
|
-
await $5({ stdio: "inherit" })
|
|
714
|
+
await $5({ stdio: isVerbose ? "inherit" : "pipe" })`${pm} ${args}`;
|
|
625
715
|
console.log("\u2705 Version bumped successfully!");
|
|
626
716
|
} catch (error) {
|
|
627
717
|
console.error("\u274C Failed to bump version.");
|
|
@@ -630,28 +720,29 @@ var versionCommand = new Command6("version").description("Bumps the package vers
|
|
|
630
720
|
});
|
|
631
721
|
|
|
632
722
|
// src/core/info.ts
|
|
633
|
-
import * as
|
|
634
|
-
import * as
|
|
723
|
+
import * as fs6 from "fs/promises";
|
|
724
|
+
import * as path6 from "path";
|
|
635
725
|
import { Command as Command7 } from "commander";
|
|
636
726
|
async function getDirSize(dirPath) {
|
|
637
727
|
let size = 0;
|
|
638
|
-
const files = await
|
|
728
|
+
const files = await fs6.readdir(dirPath, { withFileTypes: true });
|
|
639
729
|
for (const file of files) {
|
|
640
|
-
const fullPath =
|
|
730
|
+
const fullPath = path6.join(dirPath, file.name);
|
|
641
731
|
if (file.isDirectory()) {
|
|
642
732
|
size += await getDirSize(fullPath);
|
|
643
733
|
} else {
|
|
644
|
-
const stats = await
|
|
734
|
+
const stats = await fs6.stat(fullPath);
|
|
645
735
|
size += stats.size;
|
|
646
736
|
}
|
|
647
737
|
}
|
|
648
738
|
return size;
|
|
649
739
|
}
|
|
650
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";
|
|
651
742
|
const cwd = process.cwd();
|
|
652
|
-
const pkgJsonPath =
|
|
743
|
+
const pkgJsonPath = path6.join(cwd, "package.json");
|
|
653
744
|
try {
|
|
654
|
-
const packageJsonContent = await
|
|
745
|
+
const packageJsonContent = await fs6.readFile(pkgJsonPath, {
|
|
655
746
|
encoding: "utf8"
|
|
656
747
|
});
|
|
657
748
|
const packageJson = JSON.parse(packageJsonContent);
|
|
@@ -659,10 +750,11 @@ var infoCommand = new Command7("info").description("Displays size and file stati
|
|
|
659
750
|
if (!publishDirBase) {
|
|
660
751
|
throw new Error(`No publish directory specified in package.json.`);
|
|
661
752
|
}
|
|
662
|
-
const publishDir =
|
|
753
|
+
const publishDir = path6.join(cwd, publishDirBase);
|
|
663
754
|
const sizeBytes = await getDirSize(publishDir);
|
|
664
755
|
const sizeKB = (sizeBytes / 1024).toFixed(2);
|
|
665
756
|
const sizeMB = (sizeBytes / (1024 * 1024)).toFixed(2);
|
|
757
|
+
if (isVerbose) console.log(`Gathering info from ${publishDir}...`);
|
|
666
758
|
console.log(`
|
|
667
759
|
\u{1F4CA} Package Info: ${packageJson.name}`);
|
|
668
760
|
console.log(`================================`);
|
|
@@ -686,17 +778,19 @@ var infoCommand = new Command7("info").description("Displays size and file stati
|
|
|
686
778
|
});
|
|
687
779
|
|
|
688
780
|
// src/core/link.ts
|
|
689
|
-
import * as
|
|
690
|
-
import * as
|
|
781
|
+
import * as fs7 from "fs/promises";
|
|
782
|
+
import * as path7 from "path";
|
|
691
783
|
import { Command as Command8 } from "commander";
|
|
692
784
|
import { $ as $6 } from "execa";
|
|
693
785
|
var linkCommand = new Command8("link").description(
|
|
694
786
|
"Symlinks the built package directory so it can be tested in other local projects"
|
|
695
787
|
).action(async () => {
|
|
788
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
789
|
+
const pm = getPackageManager();
|
|
696
790
|
const cwd = process.cwd();
|
|
697
|
-
const pkgJsonPath =
|
|
791
|
+
const pkgJsonPath = path7.join(cwd, "package.json");
|
|
698
792
|
try {
|
|
699
|
-
const packageJsonContent = await
|
|
793
|
+
const packageJsonContent = await fs7.readFile(pkgJsonPath, {
|
|
700
794
|
encoding: "utf8"
|
|
701
795
|
});
|
|
702
796
|
const packageJson = JSON.parse(packageJsonContent);
|
|
@@ -704,18 +798,19 @@ var linkCommand = new Command8("link").description(
|
|
|
704
798
|
if (!publishDirBase) {
|
|
705
799
|
throw new Error(`No publish directory specified in package.json.`);
|
|
706
800
|
}
|
|
707
|
-
const publishDir =
|
|
708
|
-
|
|
801
|
+
const publishDir = path7.join(cwd, publishDirBase);
|
|
802
|
+
if (isVerbose)
|
|
803
|
+
console.log(`\u{1F517} Linking package from: ./${publishDirBase}...`);
|
|
709
804
|
await $6({
|
|
710
|
-
stdio: "inherit",
|
|
805
|
+
stdio: isVerbose ? "inherit" : "pipe",
|
|
711
806
|
cwd: publishDir
|
|
712
|
-
})
|
|
807
|
+
})`${pm} link`;
|
|
713
808
|
console.log(`
|
|
714
809
|
\u2705 Successfully linked!`);
|
|
715
810
|
console.log(
|
|
716
811
|
`To use this in another project, go to that project and run:`
|
|
717
812
|
);
|
|
718
|
-
console.log(`\u{1F449}
|
|
813
|
+
console.log(`\u{1F449} ${pm} link ${packageJson.name}`);
|
|
719
814
|
} catch (error) {
|
|
720
815
|
console.error("\u274C Error executing link command:");
|
|
721
816
|
if (error instanceof Error) console.error(error.message);
|
|
@@ -724,11 +819,11 @@ var linkCommand = new Command8("link").description(
|
|
|
724
819
|
});
|
|
725
820
|
|
|
726
821
|
// src/core/check-exports.ts
|
|
727
|
-
import * as
|
|
728
|
-
import * as
|
|
822
|
+
import * as fs8 from "fs/promises";
|
|
823
|
+
import * as path8 from "path";
|
|
729
824
|
import { Command as Command9 } from "commander";
|
|
730
825
|
async function fileExists(filePath) {
|
|
731
|
-
return
|
|
826
|
+
return fs8.stat(filePath).then(() => true).catch(() => false);
|
|
732
827
|
}
|
|
733
828
|
function extractPaths(exportsObj) {
|
|
734
829
|
let paths = [];
|
|
@@ -745,35 +840,36 @@ function extractPaths(exportsObj) {
|
|
|
745
840
|
var checkExportsCommand = new Command9("check-exports").description(
|
|
746
841
|
"Verifies that all files declared in package.json 'exports' actually exist in the build folder"
|
|
747
842
|
).action(async () => {
|
|
843
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
748
844
|
const cwd = process.cwd();
|
|
749
|
-
const pkgJsonPath =
|
|
845
|
+
const pkgJsonPath = path8.join(cwd, "package.json");
|
|
750
846
|
try {
|
|
751
|
-
const rootPkgContent = await
|
|
847
|
+
const rootPkgContent = await fs8.readFile(pkgJsonPath, {
|
|
752
848
|
encoding: "utf8"
|
|
753
849
|
});
|
|
754
850
|
const publishDirBase = JSON.parse(rootPkgContent).publishConfig?.directory || "build";
|
|
755
|
-
const buildPkgPath =
|
|
851
|
+
const buildPkgPath = path8.join(cwd, publishDirBase, "package.json");
|
|
756
852
|
if (!await fileExists(buildPkgPath)) {
|
|
757
853
|
throw new Error(
|
|
758
854
|
`Could not find compiled package.json at ./${publishDirBase}/package.json. Did you build first?`
|
|
759
855
|
);
|
|
760
856
|
}
|
|
761
|
-
const buildPkgContent = await
|
|
857
|
+
const buildPkgContent = await fs8.readFile(buildPkgPath, {
|
|
762
858
|
encoding: "utf8"
|
|
763
859
|
});
|
|
764
860
|
const buildPkg = JSON.parse(buildPkgContent);
|
|
765
861
|
if (!buildPkg.exports) {
|
|
766
|
-
console.log("\u26A0\uFE0F No 'exports' field found to check.");
|
|
862
|
+
if (isVerbose) console.log("\u26A0\uFE0F No 'exports' field found to check.");
|
|
767
863
|
return;
|
|
768
864
|
}
|
|
769
865
|
console.log(`\u{1F575}\uFE0F Checking exports mapping in ./${publishDirBase}...`);
|
|
770
866
|
const allPaths = extractPaths(buildPkg.exports);
|
|
771
867
|
let hasErrors = false;
|
|
772
868
|
for (const relativePath of allPaths) {
|
|
773
|
-
const absolutePath =
|
|
869
|
+
const absolutePath = path8.join(cwd, publishDirBase, relativePath);
|
|
774
870
|
const exists = await fileExists(absolutePath);
|
|
775
871
|
if (exists) {
|
|
776
|
-
console.log(` \u2705 Found: ${relativePath}`);
|
|
872
|
+
if (isVerbose) console.log(` \u2705 Found: ${relativePath}`);
|
|
777
873
|
} else {
|
|
778
874
|
console.error(` \u274C Missing: ${relativePath}`);
|
|
779
875
|
hasErrors = true;
|
|
@@ -794,7 +890,8 @@ var checkExportsCommand = new Command9("check-exports").description(
|
|
|
794
890
|
});
|
|
795
891
|
|
|
796
892
|
// src/core/watch.ts
|
|
797
|
-
import * as
|
|
893
|
+
import * as fs9 from "fs/promises";
|
|
894
|
+
import * as path9 from "path";
|
|
798
895
|
import { Command as Command10 } from "commander";
|
|
799
896
|
|
|
800
897
|
// node_modules/chokidar/index.js
|
|
@@ -887,7 +984,7 @@ var ReaddirpStream = class extends Readable {
|
|
|
887
984
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
888
985
|
const statMethod = opts.lstat ? lstat : stat5;
|
|
889
986
|
if (wantBigintFsStats) {
|
|
890
|
-
this._stat = (
|
|
987
|
+
this._stat = (path10) => statMethod(path10, { bigint: true });
|
|
891
988
|
} else {
|
|
892
989
|
this._stat = statMethod;
|
|
893
990
|
}
|
|
@@ -912,8 +1009,8 @@ var ReaddirpStream = class extends Readable {
|
|
|
912
1009
|
const par = this.parent;
|
|
913
1010
|
const fil = par && par.files;
|
|
914
1011
|
if (fil && fil.length > 0) {
|
|
915
|
-
const { path:
|
|
916
|
-
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));
|
|
917
1014
|
const awaited = await Promise.all(slice);
|
|
918
1015
|
for (const entry of awaited) {
|
|
919
1016
|
if (!entry)
|
|
@@ -953,20 +1050,20 @@ var ReaddirpStream = class extends Readable {
|
|
|
953
1050
|
this.reading = false;
|
|
954
1051
|
}
|
|
955
1052
|
}
|
|
956
|
-
async _exploreDir(
|
|
1053
|
+
async _exploreDir(path10, depth) {
|
|
957
1054
|
let files;
|
|
958
1055
|
try {
|
|
959
|
-
files = await readdir2(
|
|
1056
|
+
files = await readdir2(path10, this._rdOptions);
|
|
960
1057
|
} catch (error) {
|
|
961
1058
|
this._onError(error);
|
|
962
1059
|
}
|
|
963
|
-
return { files, depth, path:
|
|
1060
|
+
return { files, depth, path: path10 };
|
|
964
1061
|
}
|
|
965
|
-
async _formatEntry(dirent,
|
|
1062
|
+
async _formatEntry(dirent, path10) {
|
|
966
1063
|
let entry;
|
|
967
1064
|
const basename4 = this._isDirent ? dirent.name : dirent;
|
|
968
1065
|
try {
|
|
969
|
-
const fullPath = presolve(pjoin(
|
|
1066
|
+
const fullPath = presolve(pjoin(path10, basename4));
|
|
970
1067
|
entry = { path: prelative(this._root, fullPath), fullPath, basename: basename4 };
|
|
971
1068
|
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
972
1069
|
} catch (err) {
|
|
@@ -1366,16 +1463,16 @@ var delFromSet = (main2, prop, item) => {
|
|
|
1366
1463
|
};
|
|
1367
1464
|
var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
1368
1465
|
var FsWatchInstances = /* @__PURE__ */ new Map();
|
|
1369
|
-
function createFsWatchInstance(
|
|
1466
|
+
function createFsWatchInstance(path10, options, listener, errHandler, emitRaw) {
|
|
1370
1467
|
const handleEvent = (rawEvent, evPath) => {
|
|
1371
|
-
listener(
|
|
1372
|
-
emitRaw(rawEvent, evPath, { watchedPath:
|
|
1373
|
-
if (evPath &&
|
|
1374
|
-
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));
|
|
1375
1472
|
}
|
|
1376
1473
|
};
|
|
1377
1474
|
try {
|
|
1378
|
-
return fs_watch(
|
|
1475
|
+
return fs_watch(path10, {
|
|
1379
1476
|
persistent: options.persistent
|
|
1380
1477
|
}, handleEvent);
|
|
1381
1478
|
} catch (error) {
|
|
@@ -1391,12 +1488,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
|
1391
1488
|
listener(val1, val2, val3);
|
|
1392
1489
|
});
|
|
1393
1490
|
};
|
|
1394
|
-
var setFsWatchListener = (
|
|
1491
|
+
var setFsWatchListener = (path10, fullPath, options, handlers) => {
|
|
1395
1492
|
const { listener, errHandler, rawEmitter } = handlers;
|
|
1396
1493
|
let cont = FsWatchInstances.get(fullPath);
|
|
1397
1494
|
let watcher;
|
|
1398
1495
|
if (!options.persistent) {
|
|
1399
|
-
watcher = createFsWatchInstance(
|
|
1496
|
+
watcher = createFsWatchInstance(path10, options, listener, errHandler, rawEmitter);
|
|
1400
1497
|
if (!watcher)
|
|
1401
1498
|
return;
|
|
1402
1499
|
return watcher.close.bind(watcher);
|
|
@@ -1407,7 +1504,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
1407
1504
|
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
1408
1505
|
} else {
|
|
1409
1506
|
watcher = createFsWatchInstance(
|
|
1410
|
-
|
|
1507
|
+
path10,
|
|
1411
1508
|
options,
|
|
1412
1509
|
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
1413
1510
|
errHandler,
|
|
@@ -1422,7 +1519,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
1422
1519
|
cont.watcherUnusable = true;
|
|
1423
1520
|
if (isWindows && error.code === "EPERM") {
|
|
1424
1521
|
try {
|
|
1425
|
-
const fd = await open(
|
|
1522
|
+
const fd = await open(path10, "r");
|
|
1426
1523
|
await fd.close();
|
|
1427
1524
|
broadcastErr(error);
|
|
1428
1525
|
} catch (err) {
|
|
@@ -1453,7 +1550,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
1453
1550
|
};
|
|
1454
1551
|
};
|
|
1455
1552
|
var FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
1456
|
-
var setFsWatchFileListener = (
|
|
1553
|
+
var setFsWatchFileListener = (path10, fullPath, options, handlers) => {
|
|
1457
1554
|
const { listener, rawEmitter } = handlers;
|
|
1458
1555
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
1459
1556
|
const copts = cont && cont.options;
|
|
@@ -1475,7 +1572,7 @@ var setFsWatchFileListener = (path9, fullPath, options, handlers) => {
|
|
|
1475
1572
|
});
|
|
1476
1573
|
const currmtime = curr.mtimeMs;
|
|
1477
1574
|
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
1478
|
-
foreach(cont.listeners, (listener2) => listener2(
|
|
1575
|
+
foreach(cont.listeners, (listener2) => listener2(path10, curr));
|
|
1479
1576
|
}
|
|
1480
1577
|
})
|
|
1481
1578
|
};
|
|
@@ -1505,13 +1602,13 @@ var NodeFsHandler = class {
|
|
|
1505
1602
|
* @param listener on fs change
|
|
1506
1603
|
* @returns closer for the watcher instance
|
|
1507
1604
|
*/
|
|
1508
|
-
_watchWithNodeFs(
|
|
1605
|
+
_watchWithNodeFs(path10, listener) {
|
|
1509
1606
|
const opts = this.fsw.options;
|
|
1510
|
-
const directory = sp.dirname(
|
|
1511
|
-
const basename4 = sp.basename(
|
|
1607
|
+
const directory = sp.dirname(path10);
|
|
1608
|
+
const basename4 = sp.basename(path10);
|
|
1512
1609
|
const parent = this.fsw._getWatchedDir(directory);
|
|
1513
1610
|
parent.add(basename4);
|
|
1514
|
-
const absolutePath = sp.resolve(
|
|
1611
|
+
const absolutePath = sp.resolve(path10);
|
|
1515
1612
|
const options = {
|
|
1516
1613
|
persistent: opts.persistent
|
|
1517
1614
|
};
|
|
@@ -1521,12 +1618,12 @@ var NodeFsHandler = class {
|
|
|
1521
1618
|
if (opts.usePolling) {
|
|
1522
1619
|
const enableBin = opts.interval !== opts.binaryInterval;
|
|
1523
1620
|
options.interval = enableBin && isBinaryPath(basename4) ? opts.binaryInterval : opts.interval;
|
|
1524
|
-
closer = setFsWatchFileListener(
|
|
1621
|
+
closer = setFsWatchFileListener(path10, absolutePath, options, {
|
|
1525
1622
|
listener,
|
|
1526
1623
|
rawEmitter: this.fsw._emitRaw
|
|
1527
1624
|
});
|
|
1528
1625
|
} else {
|
|
1529
|
-
closer = setFsWatchListener(
|
|
1626
|
+
closer = setFsWatchListener(path10, absolutePath, options, {
|
|
1530
1627
|
listener,
|
|
1531
1628
|
errHandler: this._boundHandleError,
|
|
1532
1629
|
rawEmitter: this.fsw._emitRaw
|
|
@@ -1542,13 +1639,13 @@ var NodeFsHandler = class {
|
|
|
1542
1639
|
if (this.fsw.closed) {
|
|
1543
1640
|
return;
|
|
1544
1641
|
}
|
|
1545
|
-
const
|
|
1642
|
+
const dirname5 = sp.dirname(file);
|
|
1546
1643
|
const basename4 = sp.basename(file);
|
|
1547
|
-
const parent = this.fsw._getWatchedDir(
|
|
1644
|
+
const parent = this.fsw._getWatchedDir(dirname5);
|
|
1548
1645
|
let prevStats = stats;
|
|
1549
1646
|
if (parent.has(basename4))
|
|
1550
1647
|
return;
|
|
1551
|
-
const listener = async (
|
|
1648
|
+
const listener = async (path10, newStats) => {
|
|
1552
1649
|
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
1553
1650
|
return;
|
|
1554
1651
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
@@ -1562,16 +1659,16 @@ var NodeFsHandler = class {
|
|
|
1562
1659
|
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
1563
1660
|
}
|
|
1564
1661
|
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
1565
|
-
this.fsw._closeFile(
|
|
1662
|
+
this.fsw._closeFile(path10);
|
|
1566
1663
|
prevStats = newStats2;
|
|
1567
1664
|
const closer2 = this._watchWithNodeFs(file, listener);
|
|
1568
1665
|
if (closer2)
|
|
1569
|
-
this.fsw._addPathCloser(
|
|
1666
|
+
this.fsw._addPathCloser(path10, closer2);
|
|
1570
1667
|
} else {
|
|
1571
1668
|
prevStats = newStats2;
|
|
1572
1669
|
}
|
|
1573
1670
|
} catch (error) {
|
|
1574
|
-
this.fsw._remove(
|
|
1671
|
+
this.fsw._remove(dirname5, basename4);
|
|
1575
1672
|
}
|
|
1576
1673
|
} else if (parent.has(basename4)) {
|
|
1577
1674
|
const at = newStats.atimeMs;
|
|
@@ -1598,7 +1695,7 @@ var NodeFsHandler = class {
|
|
|
1598
1695
|
* @param item basename of this item
|
|
1599
1696
|
* @returns true if no more processing is needed for this entry.
|
|
1600
1697
|
*/
|
|
1601
|
-
async _handleSymlink(entry, directory,
|
|
1698
|
+
async _handleSymlink(entry, directory, path10, item) {
|
|
1602
1699
|
if (this.fsw.closed) {
|
|
1603
1700
|
return;
|
|
1604
1701
|
}
|
|
@@ -1608,7 +1705,7 @@ var NodeFsHandler = class {
|
|
|
1608
1705
|
this.fsw._incrReadyCount();
|
|
1609
1706
|
let linkPath;
|
|
1610
1707
|
try {
|
|
1611
|
-
linkPath = await fsrealpath(
|
|
1708
|
+
linkPath = await fsrealpath(path10);
|
|
1612
1709
|
} catch (e) {
|
|
1613
1710
|
this.fsw._emitReady();
|
|
1614
1711
|
return true;
|
|
@@ -1618,12 +1715,12 @@ var NodeFsHandler = class {
|
|
|
1618
1715
|
if (dir.has(item)) {
|
|
1619
1716
|
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
1620
1717
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
1621
|
-
this.fsw._emit(EV.CHANGE,
|
|
1718
|
+
this.fsw._emit(EV.CHANGE, path10, entry.stats);
|
|
1622
1719
|
}
|
|
1623
1720
|
} else {
|
|
1624
1721
|
dir.add(item);
|
|
1625
1722
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
1626
|
-
this.fsw._emit(EV.ADD,
|
|
1723
|
+
this.fsw._emit(EV.ADD, path10, entry.stats);
|
|
1627
1724
|
}
|
|
1628
1725
|
this.fsw._emitReady();
|
|
1629
1726
|
return true;
|
|
@@ -1653,9 +1750,9 @@ var NodeFsHandler = class {
|
|
|
1653
1750
|
return;
|
|
1654
1751
|
}
|
|
1655
1752
|
const item = entry.path;
|
|
1656
|
-
let
|
|
1753
|
+
let path10 = sp.join(directory, item);
|
|
1657
1754
|
current.add(item);
|
|
1658
|
-
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory,
|
|
1755
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path10, item)) {
|
|
1659
1756
|
return;
|
|
1660
1757
|
}
|
|
1661
1758
|
if (this.fsw.closed) {
|
|
@@ -1664,8 +1761,8 @@ var NodeFsHandler = class {
|
|
|
1664
1761
|
}
|
|
1665
1762
|
if (item === target || !target && !previous.has(item)) {
|
|
1666
1763
|
this.fsw._incrReadyCount();
|
|
1667
|
-
|
|
1668
|
-
this._addToNodeFs(
|
|
1764
|
+
path10 = sp.join(dir, sp.relative(dir, path10));
|
|
1765
|
+
this._addToNodeFs(path10, initialAdd, wh, depth + 1);
|
|
1669
1766
|
}
|
|
1670
1767
|
}).on(EV.ERROR, this._boundHandleError);
|
|
1671
1768
|
return new Promise((resolve4, reject) => {
|
|
@@ -1734,13 +1831,13 @@ var NodeFsHandler = class {
|
|
|
1734
1831
|
* @param depth Child path actually targeted for watch
|
|
1735
1832
|
* @param target Child path actually targeted for watch
|
|
1736
1833
|
*/
|
|
1737
|
-
async _addToNodeFs(
|
|
1834
|
+
async _addToNodeFs(path10, initialAdd, priorWh, depth, target) {
|
|
1738
1835
|
const ready = this.fsw._emitReady;
|
|
1739
|
-
if (this.fsw._isIgnored(
|
|
1836
|
+
if (this.fsw._isIgnored(path10) || this.fsw.closed) {
|
|
1740
1837
|
ready();
|
|
1741
1838
|
return false;
|
|
1742
1839
|
}
|
|
1743
|
-
const wh = this.fsw._getWatchHelpers(
|
|
1840
|
+
const wh = this.fsw._getWatchHelpers(path10);
|
|
1744
1841
|
if (priorWh) {
|
|
1745
1842
|
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
1746
1843
|
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
@@ -1756,8 +1853,8 @@ var NodeFsHandler = class {
|
|
|
1756
1853
|
const follow = this.fsw.options.followSymlinks;
|
|
1757
1854
|
let closer;
|
|
1758
1855
|
if (stats.isDirectory()) {
|
|
1759
|
-
const absPath = sp.resolve(
|
|
1760
|
-
const targetPath = follow ? await fsrealpath(
|
|
1856
|
+
const absPath = sp.resolve(path10);
|
|
1857
|
+
const targetPath = follow ? await fsrealpath(path10) : path10;
|
|
1761
1858
|
if (this.fsw.closed)
|
|
1762
1859
|
return;
|
|
1763
1860
|
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
@@ -1767,29 +1864,29 @@ var NodeFsHandler = class {
|
|
|
1767
1864
|
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
1768
1865
|
}
|
|
1769
1866
|
} else if (stats.isSymbolicLink()) {
|
|
1770
|
-
const targetPath = follow ? await fsrealpath(
|
|
1867
|
+
const targetPath = follow ? await fsrealpath(path10) : path10;
|
|
1771
1868
|
if (this.fsw.closed)
|
|
1772
1869
|
return;
|
|
1773
1870
|
const parent = sp.dirname(wh.watchPath);
|
|
1774
1871
|
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
1775
1872
|
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
1776
|
-
closer = await this._handleDir(parent, stats, initialAdd, depth,
|
|
1873
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path10, wh, targetPath);
|
|
1777
1874
|
if (this.fsw.closed)
|
|
1778
1875
|
return;
|
|
1779
1876
|
if (targetPath !== void 0) {
|
|
1780
|
-
this.fsw._symlinkPaths.set(sp.resolve(
|
|
1877
|
+
this.fsw._symlinkPaths.set(sp.resolve(path10), targetPath);
|
|
1781
1878
|
}
|
|
1782
1879
|
} else {
|
|
1783
1880
|
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
1784
1881
|
}
|
|
1785
1882
|
ready();
|
|
1786
1883
|
if (closer)
|
|
1787
|
-
this.fsw._addPathCloser(
|
|
1884
|
+
this.fsw._addPathCloser(path10, closer);
|
|
1788
1885
|
return false;
|
|
1789
1886
|
} catch (error) {
|
|
1790
1887
|
if (this.fsw._handleError(error)) {
|
|
1791
1888
|
ready();
|
|
1792
|
-
return
|
|
1889
|
+
return path10;
|
|
1793
1890
|
}
|
|
1794
1891
|
}
|
|
1795
1892
|
}
|
|
@@ -1821,35 +1918,35 @@ function createPattern(matcher) {
|
|
|
1821
1918
|
if (matcher.path === string)
|
|
1822
1919
|
return true;
|
|
1823
1920
|
if (matcher.recursive) {
|
|
1824
|
-
const
|
|
1825
|
-
if (!
|
|
1921
|
+
const relative4 = sp2.relative(matcher.path, string);
|
|
1922
|
+
if (!relative4) {
|
|
1826
1923
|
return false;
|
|
1827
1924
|
}
|
|
1828
|
-
return !
|
|
1925
|
+
return !relative4.startsWith("..") && !sp2.isAbsolute(relative4);
|
|
1829
1926
|
}
|
|
1830
1927
|
return false;
|
|
1831
1928
|
};
|
|
1832
1929
|
}
|
|
1833
1930
|
return () => false;
|
|
1834
1931
|
}
|
|
1835
|
-
function normalizePath(
|
|
1836
|
-
if (typeof
|
|
1932
|
+
function normalizePath(path10) {
|
|
1933
|
+
if (typeof path10 !== "string")
|
|
1837
1934
|
throw new Error("string expected");
|
|
1838
|
-
|
|
1839
|
-
|
|
1935
|
+
path10 = sp2.normalize(path10);
|
|
1936
|
+
path10 = path10.replace(/\\/g, "/");
|
|
1840
1937
|
let prepend = false;
|
|
1841
|
-
if (
|
|
1938
|
+
if (path10.startsWith("//"))
|
|
1842
1939
|
prepend = true;
|
|
1843
|
-
|
|
1940
|
+
path10 = path10.replace(DOUBLE_SLASH_RE, "/");
|
|
1844
1941
|
if (prepend)
|
|
1845
|
-
|
|
1846
|
-
return
|
|
1942
|
+
path10 = "/" + path10;
|
|
1943
|
+
return path10;
|
|
1847
1944
|
}
|
|
1848
1945
|
function matchPatterns(patterns, testString, stats) {
|
|
1849
|
-
const
|
|
1946
|
+
const path10 = normalizePath(testString);
|
|
1850
1947
|
for (let index = 0; index < patterns.length; index++) {
|
|
1851
1948
|
const pattern = patterns[index];
|
|
1852
|
-
if (pattern(
|
|
1949
|
+
if (pattern(path10, stats)) {
|
|
1853
1950
|
return true;
|
|
1854
1951
|
}
|
|
1855
1952
|
}
|
|
@@ -1887,19 +1984,19 @@ var toUnix = (string) => {
|
|
|
1887
1984
|
}
|
|
1888
1985
|
return str;
|
|
1889
1986
|
};
|
|
1890
|
-
var normalizePathToUnix = (
|
|
1891
|
-
var normalizeIgnored = (cwd = "") => (
|
|
1892
|
-
if (typeof
|
|
1893
|
-
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));
|
|
1894
1991
|
} else {
|
|
1895
|
-
return
|
|
1992
|
+
return path10;
|
|
1896
1993
|
}
|
|
1897
1994
|
};
|
|
1898
|
-
var getAbsolutePath = (
|
|
1899
|
-
if (sp2.isAbsolute(
|
|
1900
|
-
return
|
|
1995
|
+
var getAbsolutePath = (path10, cwd) => {
|
|
1996
|
+
if (sp2.isAbsolute(path10)) {
|
|
1997
|
+
return path10;
|
|
1901
1998
|
}
|
|
1902
|
-
return sp2.join(cwd,
|
|
1999
|
+
return sp2.join(cwd, path10);
|
|
1903
2000
|
};
|
|
1904
2001
|
var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
1905
2002
|
var DirEntry = class {
|
|
@@ -1964,10 +2061,10 @@ var WatchHelper = class {
|
|
|
1964
2061
|
dirParts;
|
|
1965
2062
|
followSymlinks;
|
|
1966
2063
|
statMethod;
|
|
1967
|
-
constructor(
|
|
2064
|
+
constructor(path10, follow, fsw) {
|
|
1968
2065
|
this.fsw = fsw;
|
|
1969
|
-
const watchPath =
|
|
1970
|
-
this.path =
|
|
2066
|
+
const watchPath = path10;
|
|
2067
|
+
this.path = path10 = path10.replace(REPLACER_RE, "");
|
|
1971
2068
|
this.watchPath = watchPath;
|
|
1972
2069
|
this.fullWatchPath = sp2.resolve(watchPath);
|
|
1973
2070
|
this.dirParts = [];
|
|
@@ -2107,20 +2204,20 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2107
2204
|
this._closePromise = void 0;
|
|
2108
2205
|
let paths = unifyPaths(paths_);
|
|
2109
2206
|
if (cwd) {
|
|
2110
|
-
paths = paths.map((
|
|
2111
|
-
const absPath = getAbsolutePath(
|
|
2207
|
+
paths = paths.map((path10) => {
|
|
2208
|
+
const absPath = getAbsolutePath(path10, cwd);
|
|
2112
2209
|
return absPath;
|
|
2113
2210
|
});
|
|
2114
2211
|
}
|
|
2115
|
-
paths.forEach((
|
|
2116
|
-
this._removeIgnoredPath(
|
|
2212
|
+
paths.forEach((path10) => {
|
|
2213
|
+
this._removeIgnoredPath(path10);
|
|
2117
2214
|
});
|
|
2118
2215
|
this._userIgnored = void 0;
|
|
2119
2216
|
if (!this._readyCount)
|
|
2120
2217
|
this._readyCount = 0;
|
|
2121
2218
|
this._readyCount += paths.length;
|
|
2122
|
-
Promise.all(paths.map(async (
|
|
2123
|
-
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);
|
|
2124
2221
|
if (res)
|
|
2125
2222
|
this._emitReady();
|
|
2126
2223
|
return res;
|
|
@@ -2142,17 +2239,17 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2142
2239
|
return this;
|
|
2143
2240
|
const paths = unifyPaths(paths_);
|
|
2144
2241
|
const { cwd } = this.options;
|
|
2145
|
-
paths.forEach((
|
|
2146
|
-
if (!sp2.isAbsolute(
|
|
2242
|
+
paths.forEach((path10) => {
|
|
2243
|
+
if (!sp2.isAbsolute(path10) && !this._closers.has(path10)) {
|
|
2147
2244
|
if (cwd)
|
|
2148
|
-
|
|
2149
|
-
|
|
2245
|
+
path10 = sp2.join(cwd, path10);
|
|
2246
|
+
path10 = sp2.resolve(path10);
|
|
2150
2247
|
}
|
|
2151
|
-
this._closePath(
|
|
2152
|
-
this._addIgnoredPath(
|
|
2153
|
-
if (this._watched.has(
|
|
2248
|
+
this._closePath(path10);
|
|
2249
|
+
this._addIgnoredPath(path10);
|
|
2250
|
+
if (this._watched.has(path10)) {
|
|
2154
2251
|
this._addIgnoredPath({
|
|
2155
|
-
path:
|
|
2252
|
+
path: path10,
|
|
2156
2253
|
recursive: true
|
|
2157
2254
|
});
|
|
2158
2255
|
}
|
|
@@ -2216,38 +2313,38 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2216
2313
|
* @param stats arguments to be passed with event
|
|
2217
2314
|
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
2218
2315
|
*/
|
|
2219
|
-
async _emit(event,
|
|
2316
|
+
async _emit(event, path10, stats) {
|
|
2220
2317
|
if (this.closed)
|
|
2221
2318
|
return;
|
|
2222
2319
|
const opts = this.options;
|
|
2223
2320
|
if (isWindows)
|
|
2224
|
-
|
|
2321
|
+
path10 = sp2.normalize(path10);
|
|
2225
2322
|
if (opts.cwd)
|
|
2226
|
-
|
|
2227
|
-
const args = [
|
|
2323
|
+
path10 = sp2.relative(opts.cwd, path10);
|
|
2324
|
+
const args = [path10];
|
|
2228
2325
|
if (stats != null)
|
|
2229
2326
|
args.push(stats);
|
|
2230
2327
|
const awf = opts.awaitWriteFinish;
|
|
2231
2328
|
let pw;
|
|
2232
|
-
if (awf && (pw = this._pendingWrites.get(
|
|
2329
|
+
if (awf && (pw = this._pendingWrites.get(path10))) {
|
|
2233
2330
|
pw.lastChange = /* @__PURE__ */ new Date();
|
|
2234
2331
|
return this;
|
|
2235
2332
|
}
|
|
2236
2333
|
if (opts.atomic) {
|
|
2237
2334
|
if (event === EVENTS.UNLINK) {
|
|
2238
|
-
this._pendingUnlinks.set(
|
|
2335
|
+
this._pendingUnlinks.set(path10, [event, ...args]);
|
|
2239
2336
|
setTimeout(() => {
|
|
2240
|
-
this._pendingUnlinks.forEach((entry,
|
|
2337
|
+
this._pendingUnlinks.forEach((entry, path11) => {
|
|
2241
2338
|
this.emit(...entry);
|
|
2242
2339
|
this.emit(EVENTS.ALL, ...entry);
|
|
2243
|
-
this._pendingUnlinks.delete(
|
|
2340
|
+
this._pendingUnlinks.delete(path11);
|
|
2244
2341
|
});
|
|
2245
2342
|
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
2246
2343
|
return this;
|
|
2247
2344
|
}
|
|
2248
|
-
if (event === EVENTS.ADD && this._pendingUnlinks.has(
|
|
2345
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path10)) {
|
|
2249
2346
|
event = EVENTS.CHANGE;
|
|
2250
|
-
this._pendingUnlinks.delete(
|
|
2347
|
+
this._pendingUnlinks.delete(path10);
|
|
2251
2348
|
}
|
|
2252
2349
|
}
|
|
2253
2350
|
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
@@ -2265,16 +2362,16 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2265
2362
|
this.emitWithAll(event, args);
|
|
2266
2363
|
}
|
|
2267
2364
|
};
|
|
2268
|
-
this._awaitWriteFinish(
|
|
2365
|
+
this._awaitWriteFinish(path10, awf.stabilityThreshold, event, awfEmit);
|
|
2269
2366
|
return this;
|
|
2270
2367
|
}
|
|
2271
2368
|
if (event === EVENTS.CHANGE) {
|
|
2272
|
-
const isThrottled = !this._throttle(EVENTS.CHANGE,
|
|
2369
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path10, 50);
|
|
2273
2370
|
if (isThrottled)
|
|
2274
2371
|
return this;
|
|
2275
2372
|
}
|
|
2276
2373
|
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
2277
|
-
const fullPath = opts.cwd ? sp2.join(opts.cwd,
|
|
2374
|
+
const fullPath = opts.cwd ? sp2.join(opts.cwd, path10) : path10;
|
|
2278
2375
|
let stats2;
|
|
2279
2376
|
try {
|
|
2280
2377
|
stats2 = await stat7(fullPath);
|
|
@@ -2305,23 +2402,23 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2305
2402
|
* @param timeout duration of time to suppress duplicate actions
|
|
2306
2403
|
* @returns tracking object or false if action should be suppressed
|
|
2307
2404
|
*/
|
|
2308
|
-
_throttle(actionType,
|
|
2405
|
+
_throttle(actionType, path10, timeout) {
|
|
2309
2406
|
if (!this._throttled.has(actionType)) {
|
|
2310
2407
|
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
2311
2408
|
}
|
|
2312
2409
|
const action = this._throttled.get(actionType);
|
|
2313
2410
|
if (!action)
|
|
2314
2411
|
throw new Error("invalid throttle");
|
|
2315
|
-
const actionPath = action.get(
|
|
2412
|
+
const actionPath = action.get(path10);
|
|
2316
2413
|
if (actionPath) {
|
|
2317
2414
|
actionPath.count++;
|
|
2318
2415
|
return false;
|
|
2319
2416
|
}
|
|
2320
2417
|
let timeoutObject;
|
|
2321
2418
|
const clear = () => {
|
|
2322
|
-
const item = action.get(
|
|
2419
|
+
const item = action.get(path10);
|
|
2323
2420
|
const count = item ? item.count : 0;
|
|
2324
|
-
action.delete(
|
|
2421
|
+
action.delete(path10);
|
|
2325
2422
|
clearTimeout(timeoutObject);
|
|
2326
2423
|
if (item)
|
|
2327
2424
|
clearTimeout(item.timeoutObject);
|
|
@@ -2329,7 +2426,7 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2329
2426
|
};
|
|
2330
2427
|
timeoutObject = setTimeout(clear, timeout);
|
|
2331
2428
|
const thr = { timeoutObject, clear, count: 0 };
|
|
2332
|
-
action.set(
|
|
2429
|
+
action.set(path10, thr);
|
|
2333
2430
|
return thr;
|
|
2334
2431
|
}
|
|
2335
2432
|
_incrReadyCount() {
|
|
@@ -2343,44 +2440,44 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2343
2440
|
* @param event
|
|
2344
2441
|
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
2345
2442
|
*/
|
|
2346
|
-
_awaitWriteFinish(
|
|
2443
|
+
_awaitWriteFinish(path10, threshold, event, awfEmit) {
|
|
2347
2444
|
const awf = this.options.awaitWriteFinish;
|
|
2348
2445
|
if (typeof awf !== "object")
|
|
2349
2446
|
return;
|
|
2350
2447
|
const pollInterval = awf.pollInterval;
|
|
2351
2448
|
let timeoutHandler;
|
|
2352
|
-
let fullPath =
|
|
2353
|
-
if (this.options.cwd && !sp2.isAbsolute(
|
|
2354
|
-
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);
|
|
2355
2452
|
}
|
|
2356
2453
|
const now = /* @__PURE__ */ new Date();
|
|
2357
2454
|
const writes = this._pendingWrites;
|
|
2358
2455
|
function awaitWriteFinishFn(prevStat) {
|
|
2359
2456
|
statcb(fullPath, (err, curStat) => {
|
|
2360
|
-
if (err || !writes.has(
|
|
2457
|
+
if (err || !writes.has(path10)) {
|
|
2361
2458
|
if (err && err.code !== "ENOENT")
|
|
2362
2459
|
awfEmit(err);
|
|
2363
2460
|
return;
|
|
2364
2461
|
}
|
|
2365
2462
|
const now2 = Number(/* @__PURE__ */ new Date());
|
|
2366
2463
|
if (prevStat && curStat.size !== prevStat.size) {
|
|
2367
|
-
writes.get(
|
|
2464
|
+
writes.get(path10).lastChange = now2;
|
|
2368
2465
|
}
|
|
2369
|
-
const pw = writes.get(
|
|
2466
|
+
const pw = writes.get(path10);
|
|
2370
2467
|
const df = now2 - pw.lastChange;
|
|
2371
2468
|
if (df >= threshold) {
|
|
2372
|
-
writes.delete(
|
|
2469
|
+
writes.delete(path10);
|
|
2373
2470
|
awfEmit(void 0, curStat);
|
|
2374
2471
|
} else {
|
|
2375
2472
|
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
2376
2473
|
}
|
|
2377
2474
|
});
|
|
2378
2475
|
}
|
|
2379
|
-
if (!writes.has(
|
|
2380
|
-
writes.set(
|
|
2476
|
+
if (!writes.has(path10)) {
|
|
2477
|
+
writes.set(path10, {
|
|
2381
2478
|
lastChange: now,
|
|
2382
2479
|
cancelWait: () => {
|
|
2383
|
-
writes.delete(
|
|
2480
|
+
writes.delete(path10);
|
|
2384
2481
|
clearTimeout(timeoutHandler);
|
|
2385
2482
|
return event;
|
|
2386
2483
|
}
|
|
@@ -2391,8 +2488,8 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2391
2488
|
/**
|
|
2392
2489
|
* Determines whether user has asked to ignore this path.
|
|
2393
2490
|
*/
|
|
2394
|
-
_isIgnored(
|
|
2395
|
-
if (this.options.atomic && DOT_RE.test(
|
|
2491
|
+
_isIgnored(path10, stats) {
|
|
2492
|
+
if (this.options.atomic && DOT_RE.test(path10))
|
|
2396
2493
|
return true;
|
|
2397
2494
|
if (!this._userIgnored) {
|
|
2398
2495
|
const { cwd } = this.options;
|
|
@@ -2402,17 +2499,17 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2402
2499
|
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
2403
2500
|
this._userIgnored = anymatch(list, void 0);
|
|
2404
2501
|
}
|
|
2405
|
-
return this._userIgnored(
|
|
2502
|
+
return this._userIgnored(path10, stats);
|
|
2406
2503
|
}
|
|
2407
|
-
_isntIgnored(
|
|
2408
|
-
return !this._isIgnored(
|
|
2504
|
+
_isntIgnored(path10, stat9) {
|
|
2505
|
+
return !this._isIgnored(path10, stat9);
|
|
2409
2506
|
}
|
|
2410
2507
|
/**
|
|
2411
2508
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
2412
2509
|
* @param path file or directory pattern being watched
|
|
2413
2510
|
*/
|
|
2414
|
-
_getWatchHelpers(
|
|
2415
|
-
return new WatchHelper(
|
|
2511
|
+
_getWatchHelpers(path10) {
|
|
2512
|
+
return new WatchHelper(path10, this.options.followSymlinks, this);
|
|
2416
2513
|
}
|
|
2417
2514
|
// Directory helpers
|
|
2418
2515
|
// -----------------
|
|
@@ -2444,63 +2541,63 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2444
2541
|
* @param item base path of item/directory
|
|
2445
2542
|
*/
|
|
2446
2543
|
_remove(directory, item, isDirectory) {
|
|
2447
|
-
const
|
|
2448
|
-
const fullPath = sp2.resolve(
|
|
2449
|
-
isDirectory = isDirectory != null ? isDirectory : this._watched.has(
|
|
2450
|
-
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))
|
|
2451
2548
|
return;
|
|
2452
2549
|
if (!isDirectory && this._watched.size === 1) {
|
|
2453
2550
|
this.add(directory, item, true);
|
|
2454
2551
|
}
|
|
2455
|
-
const wp = this._getWatchedDir(
|
|
2552
|
+
const wp = this._getWatchedDir(path10);
|
|
2456
2553
|
const nestedDirectoryChildren = wp.getChildren();
|
|
2457
|
-
nestedDirectoryChildren.forEach((nested) => this._remove(
|
|
2554
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path10, nested));
|
|
2458
2555
|
const parent = this._getWatchedDir(directory);
|
|
2459
2556
|
const wasTracked = parent.has(item);
|
|
2460
2557
|
parent.remove(item);
|
|
2461
2558
|
if (this._symlinkPaths.has(fullPath)) {
|
|
2462
2559
|
this._symlinkPaths.delete(fullPath);
|
|
2463
2560
|
}
|
|
2464
|
-
let relPath =
|
|
2561
|
+
let relPath = path10;
|
|
2465
2562
|
if (this.options.cwd)
|
|
2466
|
-
relPath = sp2.relative(this.options.cwd,
|
|
2563
|
+
relPath = sp2.relative(this.options.cwd, path10);
|
|
2467
2564
|
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
2468
2565
|
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
2469
2566
|
if (event === EVENTS.ADD)
|
|
2470
2567
|
return;
|
|
2471
2568
|
}
|
|
2472
|
-
this._watched.delete(
|
|
2569
|
+
this._watched.delete(path10);
|
|
2473
2570
|
this._watched.delete(fullPath);
|
|
2474
2571
|
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
2475
|
-
if (wasTracked && !this._isIgnored(
|
|
2476
|
-
this._emit(eventName,
|
|
2477
|
-
this._closePath(
|
|
2572
|
+
if (wasTracked && !this._isIgnored(path10))
|
|
2573
|
+
this._emit(eventName, path10);
|
|
2574
|
+
this._closePath(path10);
|
|
2478
2575
|
}
|
|
2479
2576
|
/**
|
|
2480
2577
|
* Closes all watchers for a path
|
|
2481
2578
|
*/
|
|
2482
|
-
_closePath(
|
|
2483
|
-
this._closeFile(
|
|
2484
|
-
const dir = sp2.dirname(
|
|
2485
|
-
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));
|
|
2486
2583
|
}
|
|
2487
2584
|
/**
|
|
2488
2585
|
* Closes only file-specific watchers
|
|
2489
2586
|
*/
|
|
2490
|
-
_closeFile(
|
|
2491
|
-
const closers = this._closers.get(
|
|
2587
|
+
_closeFile(path10) {
|
|
2588
|
+
const closers = this._closers.get(path10);
|
|
2492
2589
|
if (!closers)
|
|
2493
2590
|
return;
|
|
2494
2591
|
closers.forEach((closer) => closer());
|
|
2495
|
-
this._closers.delete(
|
|
2592
|
+
this._closers.delete(path10);
|
|
2496
2593
|
}
|
|
2497
|
-
_addPathCloser(
|
|
2594
|
+
_addPathCloser(path10, closer) {
|
|
2498
2595
|
if (!closer)
|
|
2499
2596
|
return;
|
|
2500
|
-
let list = this._closers.get(
|
|
2597
|
+
let list = this._closers.get(path10);
|
|
2501
2598
|
if (!list) {
|
|
2502
2599
|
list = [];
|
|
2503
|
-
this._closers.set(
|
|
2600
|
+
this._closers.set(path10, list);
|
|
2504
2601
|
}
|
|
2505
2602
|
list.push(closer);
|
|
2506
2603
|
}
|
|
@@ -2531,49 +2628,227 @@ var chokidar_default = { watch, FSWatcher };
|
|
|
2531
2628
|
|
|
2532
2629
|
// src/core/watch.ts
|
|
2533
2630
|
import { $ as $7 } from "execa";
|
|
2631
|
+
import { build as esbuild2 } from "esbuild";
|
|
2632
|
+
import { findWorkspacesRoot as findWorkspacesRoot2 } from "find-workspaces";
|
|
2534
2633
|
var watchCommand = new Command10("watch").description(
|
|
2535
|
-
"Watches the src directory and rebuilds
|
|
2536
|
-
).action(() => {
|
|
2634
|
+
"Watches the src directory and incrementally rebuilds files on changes (Vite-style)"
|
|
2635
|
+
).action(async () => {
|
|
2537
2636
|
const cwd = process.cwd();
|
|
2538
|
-
const srcDir =
|
|
2539
|
-
|
|
2540
|
-
let
|
|
2541
|
-
let
|
|
2542
|
-
const
|
|
2543
|
-
if (
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
\
|
|
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})...`);
|
|
2550
2667
|
try {
|
|
2551
|
-
await $7({
|
|
2552
|
-
|
|
2668
|
+
await $7({
|
|
2669
|
+
stdio: "inherit",
|
|
2670
|
+
preferLocal: true
|
|
2671
|
+
})`${pmExec} sse-tools build`;
|
|
2553
2672
|
} catch (err) {
|
|
2554
|
-
console.error(`\u274C
|
|
2555
|
-
|
|
2556
|
-
isBuilding = false;
|
|
2557
|
-
if (buildQueued) {
|
|
2558
|
-
buildQueued = false;
|
|
2559
|
-
runBuild();
|
|
2560
|
-
}
|
|
2673
|
+
console.error(`\u274C Initial build failed. Waiting for changes...
|
|
2674
|
+
`);
|
|
2561
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
|
+
});
|
|
2562
2819
|
};
|
|
2563
|
-
const
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
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();
|
|
2571
2839
|
});
|
|
2572
2840
|
|
|
2573
2841
|
// src/cli.ts
|
|
2574
2842
|
async function main() {
|
|
2575
2843
|
const program = new Command11();
|
|
2576
|
-
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
|
+
});
|
|
2577
2852
|
program.addCommand(buildCommand);
|
|
2578
2853
|
program.addCommand(publishCommand);
|
|
2579
2854
|
program.addCommand(cleanCommand);
|