@sse-ui/builder 1.1.0 → 1.3.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-6NHCDM3A.js +12 -0
- package/dist/babel-config.js +17 -13
- package/dist/{babel-QBNMMXUJ.js → chunk-6NNEV5YX.js} +33 -25
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/{chunk-44E7L73Q.js → chunk-N46AJ2OI.js} +19 -9
- package/dist/cli.js +727 -365
- 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-42L4XZEH.js +20538 -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-6NNEV5YX.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-N46AJ2OI.js";
|
|
12
|
+
import "./chunk-MLKGABMK.js";
|
|
9
13
|
|
|
10
14
|
// src/cli.ts
|
|
15
|
+
import chalk11 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,112 +92,118 @@ 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
|
-
).option("--
|
|
105
|
+
).option("--minify", "Minify the generated output.").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
|
-
|
|
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 minify = cliOptions.minify ?? fileConfig.minify ?? false;
|
|
114
|
+
const buildTypes = cliOptions.buildTypes ?? fileConfig.buildTypes ?? true;
|
|
115
|
+
const skipTsc = cliOptions.skipTsc ?? fileConfig.skipTsc ?? false;
|
|
116
|
+
const skipBundlePackageJson = cliOptions.skipBundlePackageJson ?? fileConfig.skipBundlePackageJson ?? false;
|
|
117
|
+
const skipBabelRuntimeCheck = cliOptions.skipBabelRuntimeCheck ?? false;
|
|
118
|
+
const skipPackageJson = cliOptions.skipPackageJson ?? false;
|
|
119
|
+
const enableReactCompiler = cliOptions.enableReactCompiler ?? fileConfig.babel?.enableReactCompiler ?? false;
|
|
120
|
+
const useTsgo = cliOptions.tsgo ?? fileConfig.tsgo ?? false;
|
|
121
|
+
const exportExtensions = cliOptions.exportExtensions ?? fileConfig.exportExtensions ?? [".js", ".mjs", ".cjs"];
|
|
122
|
+
const copyGlobs = [...fileConfig.copy || [], ...cliOptions.copy || []];
|
|
124
123
|
const cwd = process.cwd();
|
|
125
124
|
const pkgJsonPath = path.join(cwd, "package.json");
|
|
126
125
|
const packageJson = JSON.parse(
|
|
127
126
|
await fs.readFile(pkgJsonPath, { encoding: "utf8" })
|
|
128
127
|
);
|
|
129
128
|
validatePkgJson(packageJson, {
|
|
130
|
-
skipMainCheck:
|
|
129
|
+
skipMainCheck: cliOptions.skipMainCheck,
|
|
131
130
|
enableReactCompiler
|
|
132
131
|
});
|
|
133
132
|
const buildDirBase = packageJson.publishConfig?.directory;
|
|
134
133
|
const buildDir = path.join(cwd, buildDirBase);
|
|
135
134
|
const packageType = packageJson.type === "module" ? "module" : "commonjs";
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
if (isVerbose) {
|
|
136
|
+
console.log(chalk.blue(`Selected output directory: "${buildDirBase}"`));
|
|
137
|
+
if (isFlat)
|
|
138
|
+
console.log(chalk.blue("Building package in flat structure."));
|
|
139
139
|
}
|
|
140
140
|
await fs.rm(buildDir, { recursive: true, force: true });
|
|
141
|
+
const pm = getPackageManager();
|
|
141
142
|
let babelRuntimeVersion = packageJson.dependencies?.["@babel/runtime"];
|
|
142
143
|
if (babelRuntimeVersion === "catalog:") {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
if (pm === "pnpm") {
|
|
145
|
+
try {
|
|
146
|
+
const { stdout: configStdout } = await $`pnpm config list --json`;
|
|
147
|
+
const pnpmWorkspaceConfig = JSON.parse(configStdout);
|
|
148
|
+
babelRuntimeVersion = pnpmWorkspaceConfig.catalog["@babel/runtime"];
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (isVerbose)
|
|
151
|
+
console.warn(
|
|
152
|
+
`
|
|
153
|
+
\u26A0\uFE0F Failed to resolve 'catalog:' using pnpm. Falling back to default.`
|
|
154
|
+
);
|
|
155
|
+
babelRuntimeVersion = "^7.25.0";
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
if (isVerbose)
|
|
159
|
+
console.warn(
|
|
160
|
+
`
|
|
161
|
+
\u26A0\uFE0F 'catalog:' dependency found but package manager is ${pm}. Falling back to default babel runtime version.`
|
|
162
|
+
);
|
|
163
|
+
babelRuntimeVersion = "^7.25.0";
|
|
164
|
+
}
|
|
146
165
|
}
|
|
147
|
-
if (!babelRuntimeVersion && !skipBabelRuntimeCheck) {
|
|
166
|
+
if (builder === "babel" && !babelRuntimeVersion && !skipBabelRuntimeCheck) {
|
|
148
167
|
throw new Error(
|
|
149
168
|
"package.json needs to have a dependency on `@babel/runtime` when building with `@babel/plugin-transform-runtime`."
|
|
150
169
|
);
|
|
151
170
|
}
|
|
152
171
|
if (!bundles || bundles.length === 0) {
|
|
153
172
|
console.error(
|
|
154
|
-
|
|
173
|
+
chalk.red(
|
|
174
|
+
"No bundles specified. Use --bundle to specify which bundles to build."
|
|
175
|
+
)
|
|
155
176
|
);
|
|
156
177
|
return;
|
|
157
178
|
}
|
|
158
|
-
const {
|
|
159
|
-
const relativeOutDirs = !options.flat ? {
|
|
160
|
-
cjs: ".",
|
|
161
|
-
esm: "esm"
|
|
162
|
-
} : {
|
|
163
|
-
cjs: ".",
|
|
164
|
-
esm: "."
|
|
165
|
-
};
|
|
179
|
+
const relativeOutDirs = !isFlat ? { cjs: ".", esm: "esm" } : { cjs: ".", esm: "." };
|
|
166
180
|
const sourceDir = path.join(cwd, "src");
|
|
167
181
|
const reactVersion = semver.minVersion(packageJson.peerDependencies?.react || "")?.version ?? "latest";
|
|
168
|
-
if (enableReactCompiler) {
|
|
182
|
+
if (enableReactCompiler && isVerbose) {
|
|
169
183
|
const mode = process.env.SSE_REACT_COMPILER_MODE ?? "opt-in";
|
|
170
184
|
console.log(
|
|
171
185
|
`[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
186
|
);
|
|
173
187
|
}
|
|
174
|
-
if (
|
|
175
|
-
if (
|
|
176
|
-
console.log(
|
|
188
|
+
if (builder === "esbuild") {
|
|
189
|
+
if (isVerbose)
|
|
190
|
+
console.log(
|
|
191
|
+
chalk.green("\u{1F4E6} Bundling package into single files via esbuild...")
|
|
192
|
+
);
|
|
193
|
+
const esbuildConfig = fileConfig.esbuild || { entry: "src/index.ts" };
|
|
194
|
+
let rawEntryPoints = cliOptions.entry || esbuildConfig.entry;
|
|
195
|
+
if (!rawEntryPoints) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
chalk.red(
|
|
198
|
+
"Esbuild requires an 'entry' point. Please define it in your config (esbuild.entry) or via --entry."
|
|
199
|
+
)
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
const entryPoints = typeof rawEntryPoints === "string" ? [rawEntryPoints] : rawEntryPoints;
|
|
177
203
|
await Promise.all(
|
|
178
204
|
bundles.map(async (bundle) => {
|
|
179
205
|
const outExtension = getOutExtension(bundle, {
|
|
180
|
-
isFlat: !!
|
|
206
|
+
isFlat: !!isFlat,
|
|
181
207
|
isType: false,
|
|
182
208
|
packageType
|
|
183
209
|
});
|
|
@@ -185,18 +211,21 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
185
211
|
const outputDir = path.join(buildDir, relativeOutDir);
|
|
186
212
|
await fs.mkdir(outputDir, { recursive: true });
|
|
187
213
|
await esbuild({
|
|
188
|
-
entryPoints
|
|
214
|
+
entryPoints,
|
|
189
215
|
bundle: true,
|
|
190
|
-
|
|
216
|
+
outdir: outputDir,
|
|
191
217
|
format: bundle === "esm" ? "esm" : "cjs",
|
|
192
|
-
target: ["es2020", "node14"],
|
|
193
|
-
minify
|
|
218
|
+
target: esbuildConfig.target || ["es2020", "node14"],
|
|
219
|
+
minify,
|
|
220
|
+
outExtension: { ".js": outExtension },
|
|
221
|
+
// Forces the correct extension output
|
|
194
222
|
external: [
|
|
195
223
|
...Object.keys(packageJson.dependencies || {}),
|
|
196
|
-
...Object.keys(packageJson.peerDependencies || {})
|
|
224
|
+
...Object.keys(packageJson.peerDependencies || {}),
|
|
225
|
+
...esbuildConfig.external || []
|
|
197
226
|
]
|
|
198
227
|
});
|
|
199
|
-
if (buildDir !== outputDir && !skipBundlePackageJson && !
|
|
228
|
+
if (buildDir !== outputDir && !skipBundlePackageJson && !isFlat) {
|
|
200
229
|
await fs.writeFile(
|
|
201
230
|
path.join(outputDir, "package.json"),
|
|
202
231
|
JSON.stringify({
|
|
@@ -211,16 +240,24 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
211
240
|
name: packageJson.name,
|
|
212
241
|
version: packageJson.version,
|
|
213
242
|
outputDir,
|
|
214
|
-
isFlat: !!
|
|
243
|
+
isFlat: !!isFlat,
|
|
215
244
|
packageType
|
|
216
245
|
});
|
|
217
246
|
})
|
|
218
247
|
);
|
|
219
248
|
} else {
|
|
249
|
+
if (isVerbose)
|
|
250
|
+
console.log(chalk.green("\u{1F4E6} Transpiling package via Babel..."));
|
|
251
|
+
const { build: babelBuild, cjsCopy } = await import("./babel-6NHCDM3A.js");
|
|
252
|
+
const hasLargeFiles = cliOptions.hasLargeFiles ?? fileConfig.babel?.hasLargeFiles ?? false;
|
|
253
|
+
const extraIgnores = [
|
|
254
|
+
...fileConfig.babel?.ignore || [],
|
|
255
|
+
...cliOptions.ignore || []
|
|
256
|
+
];
|
|
220
257
|
await Promise.all(
|
|
221
258
|
bundles.map(async (bundle) => {
|
|
222
259
|
const outExtension = getOutExtension(bundle, {
|
|
223
|
-
isFlat: !!
|
|
260
|
+
isFlat: !!isFlat,
|
|
224
261
|
isType: false,
|
|
225
262
|
packageType
|
|
226
263
|
});
|
|
@@ -236,18 +273,17 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
236
273
|
babelRuntimeVersion,
|
|
237
274
|
hasLargeFiles,
|
|
238
275
|
bundle,
|
|
239
|
-
verbose,
|
|
276
|
+
verbose: isVerbose,
|
|
277
|
+
minify,
|
|
240
278
|
optimizeClsx: packageJson.dependencies?.clsx !== void 0 || packageJson.dependencies?.classnames !== void 0,
|
|
241
279
|
removePropTypes: packageJson.dependencies?.["prop-types"] !== void 0,
|
|
242
280
|
pkgVersion: packageJson.version,
|
|
243
281
|
ignores: extraIgnores,
|
|
244
282
|
outExtension,
|
|
245
|
-
reactCompiler: enableReactCompiler ? {
|
|
246
|
-
reactVersion: reactVersion || "latest"
|
|
247
|
-
} : void 0
|
|
283
|
+
reactCompiler: enableReactCompiler ? { reactVersion: reactVersion || "latest" } : void 0
|
|
248
284
|
})
|
|
249
285
|
);
|
|
250
|
-
if (buildDir !== outputDir && !skipBundlePackageJson && !
|
|
286
|
+
if (buildDir !== outputDir && !skipBundlePackageJson && !isFlat) {
|
|
251
287
|
promises.push(
|
|
252
288
|
fs.writeFile(
|
|
253
289
|
path.join(outputDir, "package.json"),
|
|
@@ -258,7 +294,7 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
258
294
|
)
|
|
259
295
|
);
|
|
260
296
|
}
|
|
261
|
-
if (!
|
|
297
|
+
if (!isFlat) {
|
|
262
298
|
promises.push(cjsCopy({ from: sourceDir, to: outputDir }));
|
|
263
299
|
}
|
|
264
300
|
await Promise.all(promises);
|
|
@@ -268,35 +304,48 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
268
304
|
name: packageJson.name,
|
|
269
305
|
version: packageJson.version,
|
|
270
306
|
outputDir,
|
|
271
|
-
isFlat: !!
|
|
307
|
+
isFlat: !!isFlat,
|
|
272
308
|
packageType
|
|
273
309
|
});
|
|
274
310
|
})
|
|
275
311
|
);
|
|
276
|
-
if (
|
|
312
|
+
if (isFlat) {
|
|
277
313
|
await cjsCopy({ from: sourceDir, to: buildDir });
|
|
278
314
|
}
|
|
279
315
|
}
|
|
280
|
-
if (buildTypes) {
|
|
281
|
-
|
|
316
|
+
if (buildTypes === true) {
|
|
317
|
+
if (isVerbose)
|
|
318
|
+
console.log(chalk.cyan("\u{1F4DD} Generating TypeScript declarations..."));
|
|
319
|
+
const tsMod = await import("./typescript-42L4XZEH.js");
|
|
282
320
|
const bundleMap = bundles.map((type) => ({
|
|
283
321
|
type,
|
|
284
322
|
dir: relativeOutDirs[type]
|
|
285
323
|
}));
|
|
324
|
+
let esbuildEntryPoints;
|
|
325
|
+
if (builder === "esbuild") {
|
|
326
|
+
const esbuildConfig = fileConfig.esbuild || { entry: "src/index.ts" };
|
|
327
|
+
const rawEntryPoints = cliOptions.entry || esbuildConfig.entry;
|
|
328
|
+
esbuildEntryPoints = typeof rawEntryPoints === "string" ? [rawEntryPoints] : rawEntryPoints;
|
|
329
|
+
}
|
|
286
330
|
await tsMod.createTypes({
|
|
287
331
|
bundles: bundleMap,
|
|
288
332
|
srcDir: sourceDir,
|
|
289
333
|
cwd,
|
|
290
334
|
skipTsc,
|
|
291
|
-
isFlat: !!
|
|
335
|
+
isFlat: !!isFlat,
|
|
292
336
|
buildDir,
|
|
293
337
|
useTsgo,
|
|
294
338
|
packageType,
|
|
295
|
-
verbose:
|
|
339
|
+
verbose: isVerbose,
|
|
340
|
+
builder,
|
|
341
|
+
entryPoints: esbuildEntryPoints
|
|
296
342
|
});
|
|
297
343
|
}
|
|
298
344
|
if (skipPackageJson) {
|
|
299
|
-
|
|
345
|
+
if (isVerbose)
|
|
346
|
+
console.log(
|
|
347
|
+
"Skipping package.json generation in the output directory."
|
|
348
|
+
);
|
|
300
349
|
return;
|
|
301
350
|
}
|
|
302
351
|
await writePackageJson({
|
|
@@ -308,16 +357,17 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
308
357
|
})),
|
|
309
358
|
outputDir: buildDir,
|
|
310
359
|
addTypes: buildTypes,
|
|
311
|
-
isFlat: !!
|
|
360
|
+
isFlat: !!isFlat,
|
|
312
361
|
packageType,
|
|
313
|
-
exportExtensions
|
|
362
|
+
exportExtensions
|
|
314
363
|
});
|
|
315
364
|
await copyHandler({
|
|
316
365
|
cwd,
|
|
317
|
-
globs:
|
|
366
|
+
globs: copyGlobs,
|
|
318
367
|
buildDir,
|
|
319
|
-
verbose:
|
|
368
|
+
verbose: isVerbose
|
|
320
369
|
});
|
|
370
|
+
console.log(chalk.green.bold("\u2714 Build completed successfully"));
|
|
321
371
|
});
|
|
322
372
|
async function copyHandler({
|
|
323
373
|
cwd,
|
|
@@ -340,13 +390,10 @@ async function copyHandler({
|
|
|
340
390
|
await Promise.all(
|
|
341
391
|
localOrRootFiles.map(async (filesToCopy) => {
|
|
342
392
|
for (const file of filesToCopy) {
|
|
343
|
-
if (
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
() => false
|
|
348
|
-
)
|
|
349
|
-
) {
|
|
393
|
+
if (await fs.stat(file).then(
|
|
394
|
+
() => true,
|
|
395
|
+
() => false
|
|
396
|
+
)) {
|
|
350
397
|
defaultFiles.push(file);
|
|
351
398
|
break;
|
|
352
399
|
}
|
|
@@ -411,7 +458,7 @@ async function copyHandler({
|
|
|
411
458
|
},
|
|
412
459
|
20
|
|
413
460
|
);
|
|
414
|
-
console.log(`\u{1F4CB} Copied ${defaultFiles.length} files.`);
|
|
461
|
+
if (verbose) console.log(`\u{1F4CB} Copied ${defaultFiles.length} files.`);
|
|
415
462
|
}
|
|
416
463
|
async function recursiveCopy({
|
|
417
464
|
source,
|
|
@@ -421,7 +468,7 @@ async function recursiveCopy({
|
|
|
421
468
|
try {
|
|
422
469
|
await fs.cp(source, target, { recursive: true });
|
|
423
470
|
if (verbose) {
|
|
424
|
-
console.log(
|
|
471
|
+
console.log(chalk.gray(`\u{1F4C4} Copied ${source} \u2192 ${target}`));
|
|
425
472
|
}
|
|
426
473
|
return true;
|
|
427
474
|
} catch (err) {
|
|
@@ -429,7 +476,7 @@ async function recursiveCopy({
|
|
|
429
476
|
throw err;
|
|
430
477
|
}
|
|
431
478
|
if (verbose) {
|
|
432
|
-
console.warn(
|
|
479
|
+
console.warn(chalk.yellow(`\u26A0 Source does not exist: ${source}`));
|
|
433
480
|
}
|
|
434
481
|
throw err;
|
|
435
482
|
}
|
|
@@ -440,12 +487,7 @@ import * as fs2 from "fs/promises";
|
|
|
440
487
|
import * as path2 from "path";
|
|
441
488
|
import { Command as Command2 } from "commander";
|
|
442
489
|
import { $ as $2 } from "execa";
|
|
443
|
-
|
|
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
|
-
}
|
|
490
|
+
import chalk2 from "chalk";
|
|
449
491
|
var publishCommand = new Command2("publish").description(
|
|
450
492
|
"Automatically publishes the built package from the publishConfig.directory"
|
|
451
493
|
).option("--tag <tag>", "Registers the published package with the given tag").option(
|
|
@@ -458,6 +500,7 @@ var publishCommand = new Command2("publish").description(
|
|
|
458
500
|
"--pm <manager>",
|
|
459
501
|
"Force a specific package manager (npm, yarn, pnpm)"
|
|
460
502
|
).action(async (options) => {
|
|
503
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
461
504
|
const cwd = process.cwd();
|
|
462
505
|
const pkgJsonPath = path2.join(cwd, "package.json");
|
|
463
506
|
try {
|
|
@@ -482,9 +525,13 @@ var publishCommand = new Command2("publish").description(
|
|
|
482
525
|
);
|
|
483
526
|
}
|
|
484
527
|
const pm = options.pm || getPackageManager();
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
528
|
+
if (isVerbose) {
|
|
529
|
+
console.log(
|
|
530
|
+
chalk2.blue(
|
|
531
|
+
`\u{1F680} Publishing via ${pm.toUpperCase()} from directory: ${publishDirBase}`
|
|
532
|
+
)
|
|
533
|
+
);
|
|
534
|
+
}
|
|
488
535
|
const args = ["publish"];
|
|
489
536
|
if (options.tag) args.push("--tag", options.tag);
|
|
490
537
|
if (options.access) args.push("--access", options.access);
|
|
@@ -496,11 +543,11 @@ var publishCommand = new Command2("publish").description(
|
|
|
496
543
|
stdio: "inherit",
|
|
497
544
|
cwd: publishDir
|
|
498
545
|
})`${pm} ${args}`;
|
|
499
|
-
console.log("\u2705 Successfully published!");
|
|
546
|
+
console.log(chalk2.green("\u2705 Successfully published!"));
|
|
500
547
|
} catch (error) {
|
|
501
|
-
console.error("\u274C Error executing publish command:");
|
|
548
|
+
console.error(chalk2.red("\u274C Error executing publish command:"));
|
|
502
549
|
if (error instanceof Error) {
|
|
503
|
-
console.error(error.message);
|
|
550
|
+
console.error(chalk2.red(error.message));
|
|
504
551
|
}
|
|
505
552
|
process.exit(1);
|
|
506
553
|
}
|
|
@@ -510,9 +557,11 @@ var publishCommand = new Command2("publish").description(
|
|
|
510
557
|
import * as fs3 from "fs/promises";
|
|
511
558
|
import * as path3 from "path";
|
|
512
559
|
import { Command as Command3 } from "commander";
|
|
560
|
+
import chalk3 from "chalk";
|
|
513
561
|
var cleanCommand = new Command3("clean").description(
|
|
514
562
|
"Removes the build directory specified in package.json to start fresh"
|
|
515
563
|
).action(async () => {
|
|
564
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
516
565
|
const cwd = process.cwd();
|
|
517
566
|
const pkgJsonPath = path3.join(cwd, "package.json");
|
|
518
567
|
try {
|
|
@@ -522,13 +571,16 @@ var cleanCommand = new Command3("clean").description(
|
|
|
522
571
|
const packageJson = JSON.parse(packageJsonContent);
|
|
523
572
|
const buildDirBase = packageJson.publishConfig?.directory || "build";
|
|
524
573
|
const buildDir = path3.join(cwd, buildDirBase);
|
|
525
|
-
|
|
574
|
+
if (isVerbose)
|
|
575
|
+
console.log(
|
|
576
|
+
chalk3.blue(`\u{1F9F9} Cleaning build directory: ${buildDirBase}...`)
|
|
577
|
+
);
|
|
526
578
|
await fs3.rm(buildDir, { recursive: true, force: true });
|
|
527
|
-
console.log("\u2728 Cleaned successfully!");
|
|
579
|
+
console.log(chalk3.green("\u2728 Cleaned successfully!"));
|
|
528
580
|
} catch (error) {
|
|
529
|
-
console.error("\u274C Error executing clean command:");
|
|
581
|
+
console.error(chalk3.red("\u274C Error executing clean command:"));
|
|
530
582
|
if (error instanceof Error) {
|
|
531
|
-
console.error(error.message);
|
|
583
|
+
console.error(chalk3.red(error.message));
|
|
532
584
|
}
|
|
533
585
|
process.exit(1);
|
|
534
586
|
}
|
|
@@ -537,10 +589,12 @@ var cleanCommand = new Command3("clean").description(
|
|
|
537
589
|
// src/core/typecheck.ts
|
|
538
590
|
import { Command as Command4 } from "commander";
|
|
539
591
|
import { $ as $3 } from "execa";
|
|
592
|
+
import chalk4 from "chalk";
|
|
540
593
|
var typecheckCommand = new Command4("typecheck").description(
|
|
541
594
|
"Runs TypeScript validation across the project without emitting files"
|
|
542
595
|
).option("--watch", "Run typechecking in watch mode").action(async (options) => {
|
|
543
|
-
|
|
596
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
597
|
+
if (isVerbose) console.log(chalk4.blue("\u{1F50D} Running typecheck..."));
|
|
544
598
|
try {
|
|
545
599
|
const args = ["tsc", "--noEmit"];
|
|
546
600
|
if (options.watch) {
|
|
@@ -548,11 +602,13 @@ var typecheckCommand = new Command4("typecheck").description(
|
|
|
548
602
|
}
|
|
549
603
|
await $3({ stdio: "inherit" })`${args.join(" ")}`;
|
|
550
604
|
if (!options.watch) {
|
|
551
|
-
console.log("\u2705 Typecheck passed! No errors found.");
|
|
605
|
+
console.log(chalk4.green("\u2705 Typecheck passed! No errors found."));
|
|
552
606
|
}
|
|
553
607
|
} catch (error) {
|
|
554
608
|
console.error(
|
|
555
|
-
|
|
609
|
+
chalk4.red(
|
|
610
|
+
"\u274C Typecheck failed. Please fix the TypeScript errors above."
|
|
611
|
+
)
|
|
556
612
|
);
|
|
557
613
|
process.exit(1);
|
|
558
614
|
}
|
|
@@ -563,9 +619,12 @@ import * as fs4 from "fs/promises";
|
|
|
563
619
|
import * as path4 from "path";
|
|
564
620
|
import { Command as Command5 } from "commander";
|
|
565
621
|
import { $ as $4 } from "execa";
|
|
622
|
+
import chalk5 from "chalk";
|
|
566
623
|
var packCommand = new Command5("pack").description(
|
|
567
624
|
"Creates a tarball (.tgz) of the built package to inspect before publishing"
|
|
568
625
|
).action(async () => {
|
|
626
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
627
|
+
const pm = getPackageManager();
|
|
569
628
|
const cwd = process.cwd();
|
|
570
629
|
const pkgJsonPath = path4.join(cwd, "package.json");
|
|
571
630
|
try {
|
|
@@ -578,28 +637,41 @@ var packCommand = new Command5("pack").description(
|
|
|
578
637
|
throw new Error(`No publish directory specified in package.json.`);
|
|
579
638
|
}
|
|
580
639
|
const publishDir = path4.join(cwd, publishDirBase);
|
|
581
|
-
|
|
640
|
+
if (isVerbose)
|
|
641
|
+
console.log(
|
|
642
|
+
chalk5.blue(`\u{1F4E6} Packing package from directory: ${publishDirBase}...`)
|
|
643
|
+
);
|
|
582
644
|
await $4({
|
|
583
645
|
stdio: "inherit",
|
|
584
646
|
cwd: publishDir
|
|
585
|
-
})
|
|
647
|
+
})`${pm} pack`;
|
|
586
648
|
console.log(
|
|
587
|
-
|
|
649
|
+
chalk5.green(
|
|
650
|
+
"\u2705 Pack successful! You can inspect the generated .tgz file."
|
|
651
|
+
)
|
|
588
652
|
);
|
|
589
653
|
} catch (error) {
|
|
590
|
-
console.error("\u274C Error executing pack command:");
|
|
591
|
-
if (error instanceof Error) console.error(error.message);
|
|
654
|
+
console.error(chalk5.red("\u274C Error executing pack command:"));
|
|
655
|
+
if (error instanceof Error) console.error(chalk5.red(error.message));
|
|
592
656
|
process.exit(1);
|
|
593
657
|
}
|
|
594
658
|
});
|
|
595
659
|
|
|
596
660
|
// src/core/version.ts
|
|
661
|
+
import * as fs5 from "fs/promises";
|
|
662
|
+
import * as path5 from "path";
|
|
597
663
|
import { Command as Command6 } from "commander";
|
|
598
664
|
import { $ as $5 } from "execa";
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
665
|
+
import enquirer from "enquirer";
|
|
666
|
+
import * as semver2 from "semver";
|
|
667
|
+
import chalk6 from "chalk";
|
|
668
|
+
var versionCommand = new Command6("version").description("Bumps the package version interactively or manually").argument(
|
|
669
|
+
"[type]",
|
|
670
|
+
"Version update type (patch, minor, major, or specific version like 1.2.3). If omitted, an interactive prompt will appear."
|
|
602
671
|
).option("--no-git-tag-version", "Do not create a git tag").action(async (type, options) => {
|
|
672
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
673
|
+
const pm = getPackageManager();
|
|
674
|
+
const cwd = process.cwd();
|
|
603
675
|
const validTypes = [
|
|
604
676
|
"patch",
|
|
605
677
|
"minor",
|
|
@@ -609,49 +681,102 @@ var versionCommand = new Command6("version").description("Bumps the package vers
|
|
|
609
681
|
"premajor",
|
|
610
682
|
"prerelease"
|
|
611
683
|
];
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
684
|
+
let selectedType = type;
|
|
685
|
+
if (!selectedType) {
|
|
686
|
+
let currentVersion = "0.0.0";
|
|
687
|
+
try {
|
|
688
|
+
const pkgJsonPath = path5.join(cwd, "package.json");
|
|
689
|
+
const pkgContent = await fs5.readFile(pkgJsonPath, "utf-8");
|
|
690
|
+
currentVersion = JSON.parse(pkgContent).version || "0.0.0";
|
|
691
|
+
} catch (err) {
|
|
692
|
+
if (isVerbose)
|
|
693
|
+
console.warn(
|
|
694
|
+
chalk6.yellow(
|
|
695
|
+
"\u26A0\uFE0F Could not read current version from package.json. Defaulting to 0.0.0"
|
|
696
|
+
)
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
const choices = validTypes.map((bump) => {
|
|
700
|
+
const nextVersion = semver2.inc(currentVersion, bump);
|
|
701
|
+
return {
|
|
702
|
+
name: bump,
|
|
703
|
+
message: `${bump.padEnd(10)} (v${nextVersion})`
|
|
704
|
+
};
|
|
705
|
+
});
|
|
706
|
+
const { bumpType } = await enquirer.prompt({
|
|
707
|
+
type: "select",
|
|
708
|
+
name: "bumpType",
|
|
709
|
+
message: `Current version: ${currentVersion}. Select version bump type:`,
|
|
710
|
+
choices: [...choices, { name: "custom", message: "custom..." }]
|
|
711
|
+
});
|
|
712
|
+
if (bumpType === "custom") {
|
|
713
|
+
const { customVersion } = await enquirer.prompt({
|
|
714
|
+
type: "input",
|
|
715
|
+
name: "customVersion",
|
|
716
|
+
message: "Enter custom version (e.g., 1.2.3):",
|
|
717
|
+
validate: (value) => {
|
|
718
|
+
if (semver2.valid(value)) {
|
|
719
|
+
return true;
|
|
720
|
+
}
|
|
721
|
+
return "Please enter a valid semver version (e.g., 1.2.3 or 1.2.3-beta.1)";
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
selectedType = customVersion;
|
|
725
|
+
} else {
|
|
726
|
+
selectedType = bumpType;
|
|
727
|
+
}
|
|
728
|
+
} else {
|
|
729
|
+
if (!validTypes.includes(selectedType) && !semver2.valid(selectedType)) {
|
|
730
|
+
console.error(
|
|
731
|
+
chalk6.red(
|
|
732
|
+
`\u274C Invalid version type: ${selectedType}. Use patch, minor, major, or a valid semver.`
|
|
733
|
+
)
|
|
734
|
+
);
|
|
735
|
+
process.exit(1);
|
|
736
|
+
}
|
|
617
737
|
}
|
|
618
|
-
|
|
738
|
+
if (isVerbose)
|
|
739
|
+
console.log(
|
|
740
|
+
chalk6.cyan(`\u{1F4C8} Bumping version (${selectedType}) via ${pm}...`)
|
|
741
|
+
);
|
|
619
742
|
try {
|
|
620
|
-
const args = ["version",
|
|
743
|
+
const args = ["version", selectedType];
|
|
621
744
|
if (!options.gitTagVersion) {
|
|
622
745
|
args.push("--no-git-tag-version");
|
|
623
746
|
}
|
|
624
|
-
await $5({ stdio: "inherit" })
|
|
625
|
-
console.log("\u2705 Version bumped successfully!");
|
|
747
|
+
await $5({ stdio: isVerbose ? "inherit" : "pipe" })`${pm} ${args}`;
|
|
748
|
+
console.log(chalk6.green("\u2705 Version bumped successfully!"));
|
|
626
749
|
} catch (error) {
|
|
627
|
-
console.error("\u274C Failed to bump version.");
|
|
750
|
+
console.error(chalk6.red("\u274C Failed to bump version."));
|
|
628
751
|
process.exit(1);
|
|
629
752
|
}
|
|
630
753
|
});
|
|
631
754
|
|
|
632
755
|
// src/core/info.ts
|
|
633
|
-
import * as
|
|
634
|
-
import * as
|
|
756
|
+
import * as fs6 from "fs/promises";
|
|
757
|
+
import * as path6 from "path";
|
|
635
758
|
import { Command as Command7 } from "commander";
|
|
759
|
+
import chalk7 from "chalk";
|
|
636
760
|
async function getDirSize(dirPath) {
|
|
637
761
|
let size = 0;
|
|
638
|
-
const files = await
|
|
762
|
+
const files = await fs6.readdir(dirPath, { withFileTypes: true });
|
|
639
763
|
for (const file of files) {
|
|
640
|
-
const fullPath =
|
|
764
|
+
const fullPath = path6.join(dirPath, file.name);
|
|
641
765
|
if (file.isDirectory()) {
|
|
642
766
|
size += await getDirSize(fullPath);
|
|
643
767
|
} else {
|
|
644
|
-
const stats = await
|
|
768
|
+
const stats = await fs6.stat(fullPath);
|
|
645
769
|
size += stats.size;
|
|
646
770
|
}
|
|
647
771
|
}
|
|
648
772
|
return size;
|
|
649
773
|
}
|
|
650
774
|
var infoCommand = new Command7("info").description("Displays size and file statistics of the built package").action(async () => {
|
|
775
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
651
776
|
const cwd = process.cwd();
|
|
652
|
-
const pkgJsonPath =
|
|
777
|
+
const pkgJsonPath = path6.join(cwd, "package.json");
|
|
653
778
|
try {
|
|
654
|
-
const packageJsonContent = await
|
|
779
|
+
const packageJsonContent = await fs6.readFile(pkgJsonPath, {
|
|
655
780
|
encoding: "utf8"
|
|
656
781
|
});
|
|
657
782
|
const packageJson = JSON.parse(packageJsonContent);
|
|
@@ -659,44 +784,53 @@ var infoCommand = new Command7("info").description("Displays size and file stati
|
|
|
659
784
|
if (!publishDirBase) {
|
|
660
785
|
throw new Error(`No publish directory specified in package.json.`);
|
|
661
786
|
}
|
|
662
|
-
const publishDir =
|
|
787
|
+
const publishDir = path6.join(cwd, publishDirBase);
|
|
663
788
|
const sizeBytes = await getDirSize(publishDir);
|
|
664
789
|
const sizeKB = (sizeBytes / 1024).toFixed(2);
|
|
665
790
|
const sizeMB = (sizeBytes / (1024 * 1024)).toFixed(2);
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
console.log(
|
|
669
|
-
|
|
670
|
-
|
|
791
|
+
if (isVerbose)
|
|
792
|
+
console.log(chalk7.gray(`Gathering info from ${publishDir}...`));
|
|
793
|
+
console.log(
|
|
794
|
+
chalk7.cyan(`
|
|
795
|
+
\u{1F4CA} Package Info: `) + chalk7.bold(packageJson.name)
|
|
796
|
+
);
|
|
797
|
+
console.log(chalk7.gray(`================================`));
|
|
798
|
+
console.log(`Version: ${chalk7.white(packageJson.version)}`);
|
|
799
|
+
console.log(`Build Folder: ${chalk7.white(`./${publishDirBase}`)}`);
|
|
671
800
|
if (sizeBytes > 1024 * 1024) {
|
|
672
801
|
console.log(
|
|
673
|
-
`Total Size: ${sizeMB} MB \u26A0\uFE0F (Consider keeping packages under 1MB)`
|
|
802
|
+
`Total Size: ${chalk7.yellow(`${sizeMB} MB`)} ${chalk7.red("\u26A0\uFE0F (Consider keeping packages under 1MB)")}`
|
|
674
803
|
);
|
|
675
804
|
} else {
|
|
676
|
-
console.log(`Total Size: ${sizeKB} KB \u2705`);
|
|
805
|
+
console.log(`Total Size: ${chalk7.green(`${sizeKB} KB \u2705`)}`);
|
|
677
806
|
}
|
|
678
|
-
console.log(`================================
|
|
679
|
-
`);
|
|
807
|
+
console.log(chalk7.gray(`================================
|
|
808
|
+
`));
|
|
680
809
|
} catch (error) {
|
|
681
810
|
console.error(
|
|
682
|
-
|
|
811
|
+
chalk7.red(
|
|
812
|
+
"\u274C Error fetching package info. Did you build the project first?"
|
|
813
|
+
)
|
|
683
814
|
);
|
|
684
815
|
process.exit(1);
|
|
685
816
|
}
|
|
686
817
|
});
|
|
687
818
|
|
|
688
819
|
// src/core/link.ts
|
|
689
|
-
import * as
|
|
690
|
-
import * as
|
|
820
|
+
import * as fs7 from "fs/promises";
|
|
821
|
+
import * as path7 from "path";
|
|
691
822
|
import { Command as Command8 } from "commander";
|
|
692
823
|
import { $ as $6 } from "execa";
|
|
824
|
+
import chalk8 from "chalk";
|
|
693
825
|
var linkCommand = new Command8("link").description(
|
|
694
826
|
"Symlinks the built package directory so it can be tested in other local projects"
|
|
695
827
|
).action(async () => {
|
|
828
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
829
|
+
const pm = getPackageManager();
|
|
696
830
|
const cwd = process.cwd();
|
|
697
|
-
const pkgJsonPath =
|
|
831
|
+
const pkgJsonPath = path7.join(cwd, "package.json");
|
|
698
832
|
try {
|
|
699
|
-
const packageJsonContent = await
|
|
833
|
+
const packageJsonContent = await fs7.readFile(pkgJsonPath, {
|
|
700
834
|
encoding: "utf8"
|
|
701
835
|
});
|
|
702
836
|
const packageJson = JSON.parse(packageJsonContent);
|
|
@@ -704,31 +838,36 @@ var linkCommand = new Command8("link").description(
|
|
|
704
838
|
if (!publishDirBase) {
|
|
705
839
|
throw new Error(`No publish directory specified in package.json.`);
|
|
706
840
|
}
|
|
707
|
-
const publishDir =
|
|
708
|
-
|
|
841
|
+
const publishDir = path7.join(cwd, publishDirBase);
|
|
842
|
+
if (isVerbose)
|
|
843
|
+
console.log(
|
|
844
|
+
chalk8.blue(`\u{1F517} Linking package from: ./${publishDirBase}...`)
|
|
845
|
+
);
|
|
709
846
|
await $6({
|
|
710
|
-
stdio: "inherit",
|
|
847
|
+
stdio: isVerbose ? "inherit" : "pipe",
|
|
711
848
|
cwd: publishDir
|
|
712
|
-
})
|
|
713
|
-
console.log(`
|
|
714
|
-
\u2705 Successfully linked!`);
|
|
849
|
+
})`${pm} link`;
|
|
850
|
+
console.log(chalk8.green(`
|
|
851
|
+
\u2705 Successfully linked!`));
|
|
715
852
|
console.log(
|
|
716
853
|
`To use this in another project, go to that project and run:`
|
|
717
854
|
);
|
|
718
|
-
console.log(`\u{1F449}
|
|
855
|
+
console.log(chalk8.cyan(`\u{1F449} ${pm} link ${packageJson.name}`));
|
|
719
856
|
} catch (error) {
|
|
720
|
-
console.error("\u274C Error executing link command:");
|
|
721
|
-
if (error instanceof Error) console.error(error.message);
|
|
857
|
+
console.error(chalk8.red("\u274C Error executing link command:"));
|
|
858
|
+
if (error instanceof Error) console.error(chalk8.red(error.message));
|
|
722
859
|
process.exit(1);
|
|
723
860
|
}
|
|
724
861
|
});
|
|
725
862
|
|
|
726
863
|
// src/core/check-exports.ts
|
|
727
|
-
import * as
|
|
728
|
-
import * as
|
|
864
|
+
import * as fs8 from "fs/promises";
|
|
865
|
+
import * as path8 from "path";
|
|
729
866
|
import { Command as Command9 } from "commander";
|
|
867
|
+
import chalk9 from "chalk";
|
|
868
|
+
import { globby as globby2 } from "globby";
|
|
730
869
|
async function fileExists(filePath) {
|
|
731
|
-
return
|
|
870
|
+
return fs8.stat(filePath).then(() => true).catch(() => false);
|
|
732
871
|
}
|
|
733
872
|
function extractPaths(exportsObj) {
|
|
734
873
|
let paths = [];
|
|
@@ -745,56 +884,85 @@ function extractPaths(exportsObj) {
|
|
|
745
884
|
var checkExportsCommand = new Command9("check-exports").description(
|
|
746
885
|
"Verifies that all files declared in package.json 'exports' actually exist in the build folder"
|
|
747
886
|
).action(async () => {
|
|
887
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
748
888
|
const cwd = process.cwd();
|
|
749
|
-
const pkgJsonPath =
|
|
889
|
+
const pkgJsonPath = path8.join(cwd, "package.json");
|
|
750
890
|
try {
|
|
751
|
-
const rootPkgContent = await
|
|
891
|
+
const rootPkgContent = await fs8.readFile(pkgJsonPath, {
|
|
752
892
|
encoding: "utf8"
|
|
753
893
|
});
|
|
754
894
|
const publishDirBase = JSON.parse(rootPkgContent).publishConfig?.directory || "build";
|
|
755
|
-
const buildPkgPath =
|
|
895
|
+
const buildPkgPath = path8.join(cwd, publishDirBase, "package.json");
|
|
756
896
|
if (!await fileExists(buildPkgPath)) {
|
|
757
897
|
throw new Error(
|
|
758
898
|
`Could not find compiled package.json at ./${publishDirBase}/package.json. Did you build first?`
|
|
759
899
|
);
|
|
760
900
|
}
|
|
761
|
-
const buildPkgContent = await
|
|
901
|
+
const buildPkgContent = await fs8.readFile(buildPkgPath, {
|
|
762
902
|
encoding: "utf8"
|
|
763
903
|
});
|
|
764
904
|
const buildPkg = JSON.parse(buildPkgContent);
|
|
765
905
|
if (!buildPkg.exports) {
|
|
766
|
-
|
|
906
|
+
if (isVerbose)
|
|
907
|
+
console.log(chalk9.yellow("\u26A0\uFE0F No 'exports' field found to check."));
|
|
767
908
|
return;
|
|
768
909
|
}
|
|
769
|
-
console.log(
|
|
910
|
+
console.log(
|
|
911
|
+
chalk9.blue(`\u{1F575}\uFE0F Checking exports mapping in ./${publishDirBase}...`)
|
|
912
|
+
);
|
|
770
913
|
const allPaths = extractPaths(buildPkg.exports);
|
|
914
|
+
const uniquePaths = Array.from(new Set(allPaths));
|
|
771
915
|
let hasErrors = false;
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
916
|
+
const publishDirFullPath = path8.join(cwd, publishDirBase);
|
|
917
|
+
for (const relativePath of uniquePaths) {
|
|
918
|
+
if (relativePath.includes("*")) {
|
|
919
|
+
const matchedFiles = await globby2(relativePath, {
|
|
920
|
+
cwd: publishDirFullPath
|
|
921
|
+
});
|
|
922
|
+
if (matchedFiles.length > 0) {
|
|
923
|
+
if (isVerbose)
|
|
924
|
+
console.log(
|
|
925
|
+
chalk9.green(` \u2705 Found matches for pattern: ${relativePath}`)
|
|
926
|
+
);
|
|
927
|
+
} else {
|
|
928
|
+
console.error(
|
|
929
|
+
chalk9.red(` \u274C No files match pattern: ${relativePath}`)
|
|
930
|
+
);
|
|
931
|
+
hasErrors = true;
|
|
932
|
+
}
|
|
777
933
|
} else {
|
|
778
|
-
|
|
779
|
-
|
|
934
|
+
const absolutePath = path8.join(publishDirFullPath, relativePath);
|
|
935
|
+
const exists = await fileExists(absolutePath);
|
|
936
|
+
if (exists) {
|
|
937
|
+
if (isVerbose)
|
|
938
|
+
console.log(chalk9.green(` \u2705 Found: ${relativePath}`));
|
|
939
|
+
} else {
|
|
940
|
+
console.error(chalk9.red(` \u274C Missing: ${relativePath}`));
|
|
941
|
+
hasErrors = true;
|
|
942
|
+
}
|
|
780
943
|
}
|
|
781
944
|
}
|
|
782
945
|
if (hasErrors) {
|
|
783
946
|
console.error(
|
|
784
|
-
|
|
947
|
+
chalk9.red(
|
|
948
|
+
"\n\u274C Export check failed! Some files declared in package.json are missing."
|
|
949
|
+
)
|
|
785
950
|
);
|
|
786
951
|
process.exit(1);
|
|
787
952
|
} else {
|
|
788
|
-
console.log(
|
|
953
|
+
console.log(
|
|
954
|
+
chalk9.green("\n\u2728 All exported files are present and accounted for!")
|
|
955
|
+
);
|
|
789
956
|
}
|
|
790
957
|
} catch (error) {
|
|
791
|
-
if (error instanceof Error) console.error(error.message);
|
|
958
|
+
if (error instanceof Error) console.error(chalk9.red(error.message));
|
|
792
959
|
process.exit(1);
|
|
793
960
|
}
|
|
794
961
|
});
|
|
795
962
|
|
|
796
963
|
// src/core/watch.ts
|
|
797
|
-
import * as
|
|
964
|
+
import * as fs9 from "fs/promises";
|
|
965
|
+
import * as path9 from "path";
|
|
798
966
|
import { Command as Command10 } from "commander";
|
|
799
967
|
|
|
800
968
|
// node_modules/chokidar/index.js
|
|
@@ -887,7 +1055,7 @@ var ReaddirpStream = class extends Readable {
|
|
|
887
1055
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
888
1056
|
const statMethod = opts.lstat ? lstat : stat5;
|
|
889
1057
|
if (wantBigintFsStats) {
|
|
890
|
-
this._stat = (
|
|
1058
|
+
this._stat = (path10) => statMethod(path10, { bigint: true });
|
|
891
1059
|
} else {
|
|
892
1060
|
this._stat = statMethod;
|
|
893
1061
|
}
|
|
@@ -912,8 +1080,8 @@ var ReaddirpStream = class extends Readable {
|
|
|
912
1080
|
const par = this.parent;
|
|
913
1081
|
const fil = par && par.files;
|
|
914
1082
|
if (fil && fil.length > 0) {
|
|
915
|
-
const { path:
|
|
916
|
-
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent,
|
|
1083
|
+
const { path: path10, depth } = par;
|
|
1084
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path10));
|
|
917
1085
|
const awaited = await Promise.all(slice);
|
|
918
1086
|
for (const entry of awaited) {
|
|
919
1087
|
if (!entry)
|
|
@@ -953,20 +1121,20 @@ var ReaddirpStream = class extends Readable {
|
|
|
953
1121
|
this.reading = false;
|
|
954
1122
|
}
|
|
955
1123
|
}
|
|
956
|
-
async _exploreDir(
|
|
1124
|
+
async _exploreDir(path10, depth) {
|
|
957
1125
|
let files;
|
|
958
1126
|
try {
|
|
959
|
-
files = await readdir2(
|
|
1127
|
+
files = await readdir2(path10, this._rdOptions);
|
|
960
1128
|
} catch (error) {
|
|
961
1129
|
this._onError(error);
|
|
962
1130
|
}
|
|
963
|
-
return { files, depth, path:
|
|
1131
|
+
return { files, depth, path: path10 };
|
|
964
1132
|
}
|
|
965
|
-
async _formatEntry(dirent,
|
|
1133
|
+
async _formatEntry(dirent, path10) {
|
|
966
1134
|
let entry;
|
|
967
1135
|
const basename4 = this._isDirent ? dirent.name : dirent;
|
|
968
1136
|
try {
|
|
969
|
-
const fullPath = presolve(pjoin(
|
|
1137
|
+
const fullPath = presolve(pjoin(path10, basename4));
|
|
970
1138
|
entry = { path: prelative(this._root, fullPath), fullPath, basename: basename4 };
|
|
971
1139
|
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
972
1140
|
} catch (err) {
|
|
@@ -1366,16 +1534,16 @@ var delFromSet = (main2, prop, item) => {
|
|
|
1366
1534
|
};
|
|
1367
1535
|
var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
1368
1536
|
var FsWatchInstances = /* @__PURE__ */ new Map();
|
|
1369
|
-
function createFsWatchInstance(
|
|
1537
|
+
function createFsWatchInstance(path10, options, listener, errHandler, emitRaw) {
|
|
1370
1538
|
const handleEvent = (rawEvent, evPath) => {
|
|
1371
|
-
listener(
|
|
1372
|
-
emitRaw(rawEvent, evPath, { watchedPath:
|
|
1373
|
-
if (evPath &&
|
|
1374
|
-
fsWatchBroadcast(sp.resolve(
|
|
1539
|
+
listener(path10);
|
|
1540
|
+
emitRaw(rawEvent, evPath, { watchedPath: path10 });
|
|
1541
|
+
if (evPath && path10 !== evPath) {
|
|
1542
|
+
fsWatchBroadcast(sp.resolve(path10, evPath), KEY_LISTENERS, sp.join(path10, evPath));
|
|
1375
1543
|
}
|
|
1376
1544
|
};
|
|
1377
1545
|
try {
|
|
1378
|
-
return fs_watch(
|
|
1546
|
+
return fs_watch(path10, {
|
|
1379
1547
|
persistent: options.persistent
|
|
1380
1548
|
}, handleEvent);
|
|
1381
1549
|
} catch (error) {
|
|
@@ -1391,12 +1559,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
|
1391
1559
|
listener(val1, val2, val3);
|
|
1392
1560
|
});
|
|
1393
1561
|
};
|
|
1394
|
-
var setFsWatchListener = (
|
|
1562
|
+
var setFsWatchListener = (path10, fullPath, options, handlers) => {
|
|
1395
1563
|
const { listener, errHandler, rawEmitter } = handlers;
|
|
1396
1564
|
let cont = FsWatchInstances.get(fullPath);
|
|
1397
1565
|
let watcher;
|
|
1398
1566
|
if (!options.persistent) {
|
|
1399
|
-
watcher = createFsWatchInstance(
|
|
1567
|
+
watcher = createFsWatchInstance(path10, options, listener, errHandler, rawEmitter);
|
|
1400
1568
|
if (!watcher)
|
|
1401
1569
|
return;
|
|
1402
1570
|
return watcher.close.bind(watcher);
|
|
@@ -1407,7 +1575,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
1407
1575
|
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
1408
1576
|
} else {
|
|
1409
1577
|
watcher = createFsWatchInstance(
|
|
1410
|
-
|
|
1578
|
+
path10,
|
|
1411
1579
|
options,
|
|
1412
1580
|
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
1413
1581
|
errHandler,
|
|
@@ -1422,7 +1590,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
1422
1590
|
cont.watcherUnusable = true;
|
|
1423
1591
|
if (isWindows && error.code === "EPERM") {
|
|
1424
1592
|
try {
|
|
1425
|
-
const fd = await open(
|
|
1593
|
+
const fd = await open(path10, "r");
|
|
1426
1594
|
await fd.close();
|
|
1427
1595
|
broadcastErr(error);
|
|
1428
1596
|
} catch (err) {
|
|
@@ -1453,7 +1621,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
1453
1621
|
};
|
|
1454
1622
|
};
|
|
1455
1623
|
var FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
1456
|
-
var setFsWatchFileListener = (
|
|
1624
|
+
var setFsWatchFileListener = (path10, fullPath, options, handlers) => {
|
|
1457
1625
|
const { listener, rawEmitter } = handlers;
|
|
1458
1626
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
1459
1627
|
const copts = cont && cont.options;
|
|
@@ -1475,7 +1643,7 @@ var setFsWatchFileListener = (path9, fullPath, options, handlers) => {
|
|
|
1475
1643
|
});
|
|
1476
1644
|
const currmtime = curr.mtimeMs;
|
|
1477
1645
|
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
1478
|
-
foreach(cont.listeners, (listener2) => listener2(
|
|
1646
|
+
foreach(cont.listeners, (listener2) => listener2(path10, curr));
|
|
1479
1647
|
}
|
|
1480
1648
|
})
|
|
1481
1649
|
};
|
|
@@ -1505,13 +1673,13 @@ var NodeFsHandler = class {
|
|
|
1505
1673
|
* @param listener on fs change
|
|
1506
1674
|
* @returns closer for the watcher instance
|
|
1507
1675
|
*/
|
|
1508
|
-
_watchWithNodeFs(
|
|
1676
|
+
_watchWithNodeFs(path10, listener) {
|
|
1509
1677
|
const opts = this.fsw.options;
|
|
1510
|
-
const directory = sp.dirname(
|
|
1511
|
-
const basename4 = sp.basename(
|
|
1678
|
+
const directory = sp.dirname(path10);
|
|
1679
|
+
const basename4 = sp.basename(path10);
|
|
1512
1680
|
const parent = this.fsw._getWatchedDir(directory);
|
|
1513
1681
|
parent.add(basename4);
|
|
1514
|
-
const absolutePath = sp.resolve(
|
|
1682
|
+
const absolutePath = sp.resolve(path10);
|
|
1515
1683
|
const options = {
|
|
1516
1684
|
persistent: opts.persistent
|
|
1517
1685
|
};
|
|
@@ -1521,12 +1689,12 @@ var NodeFsHandler = class {
|
|
|
1521
1689
|
if (opts.usePolling) {
|
|
1522
1690
|
const enableBin = opts.interval !== opts.binaryInterval;
|
|
1523
1691
|
options.interval = enableBin && isBinaryPath(basename4) ? opts.binaryInterval : opts.interval;
|
|
1524
|
-
closer = setFsWatchFileListener(
|
|
1692
|
+
closer = setFsWatchFileListener(path10, absolutePath, options, {
|
|
1525
1693
|
listener,
|
|
1526
1694
|
rawEmitter: this.fsw._emitRaw
|
|
1527
1695
|
});
|
|
1528
1696
|
} else {
|
|
1529
|
-
closer = setFsWatchListener(
|
|
1697
|
+
closer = setFsWatchListener(path10, absolutePath, options, {
|
|
1530
1698
|
listener,
|
|
1531
1699
|
errHandler: this._boundHandleError,
|
|
1532
1700
|
rawEmitter: this.fsw._emitRaw
|
|
@@ -1542,13 +1710,13 @@ var NodeFsHandler = class {
|
|
|
1542
1710
|
if (this.fsw.closed) {
|
|
1543
1711
|
return;
|
|
1544
1712
|
}
|
|
1545
|
-
const
|
|
1713
|
+
const dirname5 = sp.dirname(file);
|
|
1546
1714
|
const basename4 = sp.basename(file);
|
|
1547
|
-
const parent = this.fsw._getWatchedDir(
|
|
1715
|
+
const parent = this.fsw._getWatchedDir(dirname5);
|
|
1548
1716
|
let prevStats = stats;
|
|
1549
1717
|
if (parent.has(basename4))
|
|
1550
1718
|
return;
|
|
1551
|
-
const listener = async (
|
|
1719
|
+
const listener = async (path10, newStats) => {
|
|
1552
1720
|
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
1553
1721
|
return;
|
|
1554
1722
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
@@ -1562,16 +1730,16 @@ var NodeFsHandler = class {
|
|
|
1562
1730
|
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
1563
1731
|
}
|
|
1564
1732
|
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
1565
|
-
this.fsw._closeFile(
|
|
1733
|
+
this.fsw._closeFile(path10);
|
|
1566
1734
|
prevStats = newStats2;
|
|
1567
1735
|
const closer2 = this._watchWithNodeFs(file, listener);
|
|
1568
1736
|
if (closer2)
|
|
1569
|
-
this.fsw._addPathCloser(
|
|
1737
|
+
this.fsw._addPathCloser(path10, closer2);
|
|
1570
1738
|
} else {
|
|
1571
1739
|
prevStats = newStats2;
|
|
1572
1740
|
}
|
|
1573
1741
|
} catch (error) {
|
|
1574
|
-
this.fsw._remove(
|
|
1742
|
+
this.fsw._remove(dirname5, basename4);
|
|
1575
1743
|
}
|
|
1576
1744
|
} else if (parent.has(basename4)) {
|
|
1577
1745
|
const at = newStats.atimeMs;
|
|
@@ -1598,7 +1766,7 @@ var NodeFsHandler = class {
|
|
|
1598
1766
|
* @param item basename of this item
|
|
1599
1767
|
* @returns true if no more processing is needed for this entry.
|
|
1600
1768
|
*/
|
|
1601
|
-
async _handleSymlink(entry, directory,
|
|
1769
|
+
async _handleSymlink(entry, directory, path10, item) {
|
|
1602
1770
|
if (this.fsw.closed) {
|
|
1603
1771
|
return;
|
|
1604
1772
|
}
|
|
@@ -1608,7 +1776,7 @@ var NodeFsHandler = class {
|
|
|
1608
1776
|
this.fsw._incrReadyCount();
|
|
1609
1777
|
let linkPath;
|
|
1610
1778
|
try {
|
|
1611
|
-
linkPath = await fsrealpath(
|
|
1779
|
+
linkPath = await fsrealpath(path10);
|
|
1612
1780
|
} catch (e) {
|
|
1613
1781
|
this.fsw._emitReady();
|
|
1614
1782
|
return true;
|
|
@@ -1618,12 +1786,12 @@ var NodeFsHandler = class {
|
|
|
1618
1786
|
if (dir.has(item)) {
|
|
1619
1787
|
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
1620
1788
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
1621
|
-
this.fsw._emit(EV.CHANGE,
|
|
1789
|
+
this.fsw._emit(EV.CHANGE, path10, entry.stats);
|
|
1622
1790
|
}
|
|
1623
1791
|
} else {
|
|
1624
1792
|
dir.add(item);
|
|
1625
1793
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
1626
|
-
this.fsw._emit(EV.ADD,
|
|
1794
|
+
this.fsw._emit(EV.ADD, path10, entry.stats);
|
|
1627
1795
|
}
|
|
1628
1796
|
this.fsw._emitReady();
|
|
1629
1797
|
return true;
|
|
@@ -1653,9 +1821,9 @@ var NodeFsHandler = class {
|
|
|
1653
1821
|
return;
|
|
1654
1822
|
}
|
|
1655
1823
|
const item = entry.path;
|
|
1656
|
-
let
|
|
1824
|
+
let path10 = sp.join(directory, item);
|
|
1657
1825
|
current.add(item);
|
|
1658
|
-
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory,
|
|
1826
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path10, item)) {
|
|
1659
1827
|
return;
|
|
1660
1828
|
}
|
|
1661
1829
|
if (this.fsw.closed) {
|
|
@@ -1664,8 +1832,8 @@ var NodeFsHandler = class {
|
|
|
1664
1832
|
}
|
|
1665
1833
|
if (item === target || !target && !previous.has(item)) {
|
|
1666
1834
|
this.fsw._incrReadyCount();
|
|
1667
|
-
|
|
1668
|
-
this._addToNodeFs(
|
|
1835
|
+
path10 = sp.join(dir, sp.relative(dir, path10));
|
|
1836
|
+
this._addToNodeFs(path10, initialAdd, wh, depth + 1);
|
|
1669
1837
|
}
|
|
1670
1838
|
}).on(EV.ERROR, this._boundHandleError);
|
|
1671
1839
|
return new Promise((resolve4, reject) => {
|
|
@@ -1734,13 +1902,13 @@ var NodeFsHandler = class {
|
|
|
1734
1902
|
* @param depth Child path actually targeted for watch
|
|
1735
1903
|
* @param target Child path actually targeted for watch
|
|
1736
1904
|
*/
|
|
1737
|
-
async _addToNodeFs(
|
|
1905
|
+
async _addToNodeFs(path10, initialAdd, priorWh, depth, target) {
|
|
1738
1906
|
const ready = this.fsw._emitReady;
|
|
1739
|
-
if (this.fsw._isIgnored(
|
|
1907
|
+
if (this.fsw._isIgnored(path10) || this.fsw.closed) {
|
|
1740
1908
|
ready();
|
|
1741
1909
|
return false;
|
|
1742
1910
|
}
|
|
1743
|
-
const wh = this.fsw._getWatchHelpers(
|
|
1911
|
+
const wh = this.fsw._getWatchHelpers(path10);
|
|
1744
1912
|
if (priorWh) {
|
|
1745
1913
|
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
1746
1914
|
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
@@ -1756,8 +1924,8 @@ var NodeFsHandler = class {
|
|
|
1756
1924
|
const follow = this.fsw.options.followSymlinks;
|
|
1757
1925
|
let closer;
|
|
1758
1926
|
if (stats.isDirectory()) {
|
|
1759
|
-
const absPath = sp.resolve(
|
|
1760
|
-
const targetPath = follow ? await fsrealpath(
|
|
1927
|
+
const absPath = sp.resolve(path10);
|
|
1928
|
+
const targetPath = follow ? await fsrealpath(path10) : path10;
|
|
1761
1929
|
if (this.fsw.closed)
|
|
1762
1930
|
return;
|
|
1763
1931
|
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
@@ -1767,29 +1935,29 @@ var NodeFsHandler = class {
|
|
|
1767
1935
|
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
1768
1936
|
}
|
|
1769
1937
|
} else if (stats.isSymbolicLink()) {
|
|
1770
|
-
const targetPath = follow ? await fsrealpath(
|
|
1938
|
+
const targetPath = follow ? await fsrealpath(path10) : path10;
|
|
1771
1939
|
if (this.fsw.closed)
|
|
1772
1940
|
return;
|
|
1773
1941
|
const parent = sp.dirname(wh.watchPath);
|
|
1774
1942
|
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
1775
1943
|
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
1776
|
-
closer = await this._handleDir(parent, stats, initialAdd, depth,
|
|
1944
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path10, wh, targetPath);
|
|
1777
1945
|
if (this.fsw.closed)
|
|
1778
1946
|
return;
|
|
1779
1947
|
if (targetPath !== void 0) {
|
|
1780
|
-
this.fsw._symlinkPaths.set(sp.resolve(
|
|
1948
|
+
this.fsw._symlinkPaths.set(sp.resolve(path10), targetPath);
|
|
1781
1949
|
}
|
|
1782
1950
|
} else {
|
|
1783
1951
|
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
1784
1952
|
}
|
|
1785
1953
|
ready();
|
|
1786
1954
|
if (closer)
|
|
1787
|
-
this.fsw._addPathCloser(
|
|
1955
|
+
this.fsw._addPathCloser(path10, closer);
|
|
1788
1956
|
return false;
|
|
1789
1957
|
} catch (error) {
|
|
1790
1958
|
if (this.fsw._handleError(error)) {
|
|
1791
1959
|
ready();
|
|
1792
|
-
return
|
|
1960
|
+
return path10;
|
|
1793
1961
|
}
|
|
1794
1962
|
}
|
|
1795
1963
|
}
|
|
@@ -1821,35 +1989,35 @@ function createPattern(matcher) {
|
|
|
1821
1989
|
if (matcher.path === string)
|
|
1822
1990
|
return true;
|
|
1823
1991
|
if (matcher.recursive) {
|
|
1824
|
-
const
|
|
1825
|
-
if (!
|
|
1992
|
+
const relative4 = sp2.relative(matcher.path, string);
|
|
1993
|
+
if (!relative4) {
|
|
1826
1994
|
return false;
|
|
1827
1995
|
}
|
|
1828
|
-
return !
|
|
1996
|
+
return !relative4.startsWith("..") && !sp2.isAbsolute(relative4);
|
|
1829
1997
|
}
|
|
1830
1998
|
return false;
|
|
1831
1999
|
};
|
|
1832
2000
|
}
|
|
1833
2001
|
return () => false;
|
|
1834
2002
|
}
|
|
1835
|
-
function normalizePath(
|
|
1836
|
-
if (typeof
|
|
2003
|
+
function normalizePath(path10) {
|
|
2004
|
+
if (typeof path10 !== "string")
|
|
1837
2005
|
throw new Error("string expected");
|
|
1838
|
-
|
|
1839
|
-
|
|
2006
|
+
path10 = sp2.normalize(path10);
|
|
2007
|
+
path10 = path10.replace(/\\/g, "/");
|
|
1840
2008
|
let prepend = false;
|
|
1841
|
-
if (
|
|
2009
|
+
if (path10.startsWith("//"))
|
|
1842
2010
|
prepend = true;
|
|
1843
|
-
|
|
2011
|
+
path10 = path10.replace(DOUBLE_SLASH_RE, "/");
|
|
1844
2012
|
if (prepend)
|
|
1845
|
-
|
|
1846
|
-
return
|
|
2013
|
+
path10 = "/" + path10;
|
|
2014
|
+
return path10;
|
|
1847
2015
|
}
|
|
1848
2016
|
function matchPatterns(patterns, testString, stats) {
|
|
1849
|
-
const
|
|
2017
|
+
const path10 = normalizePath(testString);
|
|
1850
2018
|
for (let index = 0; index < patterns.length; index++) {
|
|
1851
2019
|
const pattern = patterns[index];
|
|
1852
|
-
if (pattern(
|
|
2020
|
+
if (pattern(path10, stats)) {
|
|
1853
2021
|
return true;
|
|
1854
2022
|
}
|
|
1855
2023
|
}
|
|
@@ -1887,19 +2055,19 @@ var toUnix = (string) => {
|
|
|
1887
2055
|
}
|
|
1888
2056
|
return str;
|
|
1889
2057
|
};
|
|
1890
|
-
var normalizePathToUnix = (
|
|
1891
|
-
var normalizeIgnored = (cwd = "") => (
|
|
1892
|
-
if (typeof
|
|
1893
|
-
return normalizePathToUnix(sp2.isAbsolute(
|
|
2058
|
+
var normalizePathToUnix = (path10) => toUnix(sp2.normalize(toUnix(path10)));
|
|
2059
|
+
var normalizeIgnored = (cwd = "") => (path10) => {
|
|
2060
|
+
if (typeof path10 === "string") {
|
|
2061
|
+
return normalizePathToUnix(sp2.isAbsolute(path10) ? path10 : sp2.join(cwd, path10));
|
|
1894
2062
|
} else {
|
|
1895
|
-
return
|
|
2063
|
+
return path10;
|
|
1896
2064
|
}
|
|
1897
2065
|
};
|
|
1898
|
-
var getAbsolutePath = (
|
|
1899
|
-
if (sp2.isAbsolute(
|
|
1900
|
-
return
|
|
2066
|
+
var getAbsolutePath = (path10, cwd) => {
|
|
2067
|
+
if (sp2.isAbsolute(path10)) {
|
|
2068
|
+
return path10;
|
|
1901
2069
|
}
|
|
1902
|
-
return sp2.join(cwd,
|
|
2070
|
+
return sp2.join(cwd, path10);
|
|
1903
2071
|
};
|
|
1904
2072
|
var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
1905
2073
|
var DirEntry = class {
|
|
@@ -1964,10 +2132,10 @@ var WatchHelper = class {
|
|
|
1964
2132
|
dirParts;
|
|
1965
2133
|
followSymlinks;
|
|
1966
2134
|
statMethod;
|
|
1967
|
-
constructor(
|
|
2135
|
+
constructor(path10, follow, fsw) {
|
|
1968
2136
|
this.fsw = fsw;
|
|
1969
|
-
const watchPath =
|
|
1970
|
-
this.path =
|
|
2137
|
+
const watchPath = path10;
|
|
2138
|
+
this.path = path10 = path10.replace(REPLACER_RE, "");
|
|
1971
2139
|
this.watchPath = watchPath;
|
|
1972
2140
|
this.fullWatchPath = sp2.resolve(watchPath);
|
|
1973
2141
|
this.dirParts = [];
|
|
@@ -2107,20 +2275,20 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2107
2275
|
this._closePromise = void 0;
|
|
2108
2276
|
let paths = unifyPaths(paths_);
|
|
2109
2277
|
if (cwd) {
|
|
2110
|
-
paths = paths.map((
|
|
2111
|
-
const absPath = getAbsolutePath(
|
|
2278
|
+
paths = paths.map((path10) => {
|
|
2279
|
+
const absPath = getAbsolutePath(path10, cwd);
|
|
2112
2280
|
return absPath;
|
|
2113
2281
|
});
|
|
2114
2282
|
}
|
|
2115
|
-
paths.forEach((
|
|
2116
|
-
this._removeIgnoredPath(
|
|
2283
|
+
paths.forEach((path10) => {
|
|
2284
|
+
this._removeIgnoredPath(path10);
|
|
2117
2285
|
});
|
|
2118
2286
|
this._userIgnored = void 0;
|
|
2119
2287
|
if (!this._readyCount)
|
|
2120
2288
|
this._readyCount = 0;
|
|
2121
2289
|
this._readyCount += paths.length;
|
|
2122
|
-
Promise.all(paths.map(async (
|
|
2123
|
-
const res = await this._nodeFsHandler._addToNodeFs(
|
|
2290
|
+
Promise.all(paths.map(async (path10) => {
|
|
2291
|
+
const res = await this._nodeFsHandler._addToNodeFs(path10, !_internal, void 0, 0, _origAdd);
|
|
2124
2292
|
if (res)
|
|
2125
2293
|
this._emitReady();
|
|
2126
2294
|
return res;
|
|
@@ -2142,17 +2310,17 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2142
2310
|
return this;
|
|
2143
2311
|
const paths = unifyPaths(paths_);
|
|
2144
2312
|
const { cwd } = this.options;
|
|
2145
|
-
paths.forEach((
|
|
2146
|
-
if (!sp2.isAbsolute(
|
|
2313
|
+
paths.forEach((path10) => {
|
|
2314
|
+
if (!sp2.isAbsolute(path10) && !this._closers.has(path10)) {
|
|
2147
2315
|
if (cwd)
|
|
2148
|
-
|
|
2149
|
-
|
|
2316
|
+
path10 = sp2.join(cwd, path10);
|
|
2317
|
+
path10 = sp2.resolve(path10);
|
|
2150
2318
|
}
|
|
2151
|
-
this._closePath(
|
|
2152
|
-
this._addIgnoredPath(
|
|
2153
|
-
if (this._watched.has(
|
|
2319
|
+
this._closePath(path10);
|
|
2320
|
+
this._addIgnoredPath(path10);
|
|
2321
|
+
if (this._watched.has(path10)) {
|
|
2154
2322
|
this._addIgnoredPath({
|
|
2155
|
-
path:
|
|
2323
|
+
path: path10,
|
|
2156
2324
|
recursive: true
|
|
2157
2325
|
});
|
|
2158
2326
|
}
|
|
@@ -2216,38 +2384,38 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2216
2384
|
* @param stats arguments to be passed with event
|
|
2217
2385
|
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
2218
2386
|
*/
|
|
2219
|
-
async _emit(event,
|
|
2387
|
+
async _emit(event, path10, stats) {
|
|
2220
2388
|
if (this.closed)
|
|
2221
2389
|
return;
|
|
2222
2390
|
const opts = this.options;
|
|
2223
2391
|
if (isWindows)
|
|
2224
|
-
|
|
2392
|
+
path10 = sp2.normalize(path10);
|
|
2225
2393
|
if (opts.cwd)
|
|
2226
|
-
|
|
2227
|
-
const args = [
|
|
2394
|
+
path10 = sp2.relative(opts.cwd, path10);
|
|
2395
|
+
const args = [path10];
|
|
2228
2396
|
if (stats != null)
|
|
2229
2397
|
args.push(stats);
|
|
2230
2398
|
const awf = opts.awaitWriteFinish;
|
|
2231
2399
|
let pw;
|
|
2232
|
-
if (awf && (pw = this._pendingWrites.get(
|
|
2400
|
+
if (awf && (pw = this._pendingWrites.get(path10))) {
|
|
2233
2401
|
pw.lastChange = /* @__PURE__ */ new Date();
|
|
2234
2402
|
return this;
|
|
2235
2403
|
}
|
|
2236
2404
|
if (opts.atomic) {
|
|
2237
2405
|
if (event === EVENTS.UNLINK) {
|
|
2238
|
-
this._pendingUnlinks.set(
|
|
2406
|
+
this._pendingUnlinks.set(path10, [event, ...args]);
|
|
2239
2407
|
setTimeout(() => {
|
|
2240
|
-
this._pendingUnlinks.forEach((entry,
|
|
2408
|
+
this._pendingUnlinks.forEach((entry, path11) => {
|
|
2241
2409
|
this.emit(...entry);
|
|
2242
2410
|
this.emit(EVENTS.ALL, ...entry);
|
|
2243
|
-
this._pendingUnlinks.delete(
|
|
2411
|
+
this._pendingUnlinks.delete(path11);
|
|
2244
2412
|
});
|
|
2245
2413
|
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
2246
2414
|
return this;
|
|
2247
2415
|
}
|
|
2248
|
-
if (event === EVENTS.ADD && this._pendingUnlinks.has(
|
|
2416
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path10)) {
|
|
2249
2417
|
event = EVENTS.CHANGE;
|
|
2250
|
-
this._pendingUnlinks.delete(
|
|
2418
|
+
this._pendingUnlinks.delete(path10);
|
|
2251
2419
|
}
|
|
2252
2420
|
}
|
|
2253
2421
|
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
@@ -2265,16 +2433,16 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2265
2433
|
this.emitWithAll(event, args);
|
|
2266
2434
|
}
|
|
2267
2435
|
};
|
|
2268
|
-
this._awaitWriteFinish(
|
|
2436
|
+
this._awaitWriteFinish(path10, awf.stabilityThreshold, event, awfEmit);
|
|
2269
2437
|
return this;
|
|
2270
2438
|
}
|
|
2271
2439
|
if (event === EVENTS.CHANGE) {
|
|
2272
|
-
const isThrottled = !this._throttle(EVENTS.CHANGE,
|
|
2440
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path10, 50);
|
|
2273
2441
|
if (isThrottled)
|
|
2274
2442
|
return this;
|
|
2275
2443
|
}
|
|
2276
2444
|
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,
|
|
2445
|
+
const fullPath = opts.cwd ? sp2.join(opts.cwd, path10) : path10;
|
|
2278
2446
|
let stats2;
|
|
2279
2447
|
try {
|
|
2280
2448
|
stats2 = await stat7(fullPath);
|
|
@@ -2305,23 +2473,23 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2305
2473
|
* @param timeout duration of time to suppress duplicate actions
|
|
2306
2474
|
* @returns tracking object or false if action should be suppressed
|
|
2307
2475
|
*/
|
|
2308
|
-
_throttle(actionType,
|
|
2476
|
+
_throttle(actionType, path10, timeout) {
|
|
2309
2477
|
if (!this._throttled.has(actionType)) {
|
|
2310
2478
|
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
2311
2479
|
}
|
|
2312
2480
|
const action = this._throttled.get(actionType);
|
|
2313
2481
|
if (!action)
|
|
2314
2482
|
throw new Error("invalid throttle");
|
|
2315
|
-
const actionPath = action.get(
|
|
2483
|
+
const actionPath = action.get(path10);
|
|
2316
2484
|
if (actionPath) {
|
|
2317
2485
|
actionPath.count++;
|
|
2318
2486
|
return false;
|
|
2319
2487
|
}
|
|
2320
2488
|
let timeoutObject;
|
|
2321
2489
|
const clear = () => {
|
|
2322
|
-
const item = action.get(
|
|
2490
|
+
const item = action.get(path10);
|
|
2323
2491
|
const count = item ? item.count : 0;
|
|
2324
|
-
action.delete(
|
|
2492
|
+
action.delete(path10);
|
|
2325
2493
|
clearTimeout(timeoutObject);
|
|
2326
2494
|
if (item)
|
|
2327
2495
|
clearTimeout(item.timeoutObject);
|
|
@@ -2329,7 +2497,7 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2329
2497
|
};
|
|
2330
2498
|
timeoutObject = setTimeout(clear, timeout);
|
|
2331
2499
|
const thr = { timeoutObject, clear, count: 0 };
|
|
2332
|
-
action.set(
|
|
2500
|
+
action.set(path10, thr);
|
|
2333
2501
|
return thr;
|
|
2334
2502
|
}
|
|
2335
2503
|
_incrReadyCount() {
|
|
@@ -2343,44 +2511,44 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2343
2511
|
* @param event
|
|
2344
2512
|
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
2345
2513
|
*/
|
|
2346
|
-
_awaitWriteFinish(
|
|
2514
|
+
_awaitWriteFinish(path10, threshold, event, awfEmit) {
|
|
2347
2515
|
const awf = this.options.awaitWriteFinish;
|
|
2348
2516
|
if (typeof awf !== "object")
|
|
2349
2517
|
return;
|
|
2350
2518
|
const pollInterval = awf.pollInterval;
|
|
2351
2519
|
let timeoutHandler;
|
|
2352
|
-
let fullPath =
|
|
2353
|
-
if (this.options.cwd && !sp2.isAbsolute(
|
|
2354
|
-
fullPath = sp2.join(this.options.cwd,
|
|
2520
|
+
let fullPath = path10;
|
|
2521
|
+
if (this.options.cwd && !sp2.isAbsolute(path10)) {
|
|
2522
|
+
fullPath = sp2.join(this.options.cwd, path10);
|
|
2355
2523
|
}
|
|
2356
2524
|
const now = /* @__PURE__ */ new Date();
|
|
2357
2525
|
const writes = this._pendingWrites;
|
|
2358
2526
|
function awaitWriteFinishFn(prevStat) {
|
|
2359
2527
|
statcb(fullPath, (err, curStat) => {
|
|
2360
|
-
if (err || !writes.has(
|
|
2528
|
+
if (err || !writes.has(path10)) {
|
|
2361
2529
|
if (err && err.code !== "ENOENT")
|
|
2362
2530
|
awfEmit(err);
|
|
2363
2531
|
return;
|
|
2364
2532
|
}
|
|
2365
2533
|
const now2 = Number(/* @__PURE__ */ new Date());
|
|
2366
2534
|
if (prevStat && curStat.size !== prevStat.size) {
|
|
2367
|
-
writes.get(
|
|
2535
|
+
writes.get(path10).lastChange = now2;
|
|
2368
2536
|
}
|
|
2369
|
-
const pw = writes.get(
|
|
2537
|
+
const pw = writes.get(path10);
|
|
2370
2538
|
const df = now2 - pw.lastChange;
|
|
2371
2539
|
if (df >= threshold) {
|
|
2372
|
-
writes.delete(
|
|
2540
|
+
writes.delete(path10);
|
|
2373
2541
|
awfEmit(void 0, curStat);
|
|
2374
2542
|
} else {
|
|
2375
2543
|
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
2376
2544
|
}
|
|
2377
2545
|
});
|
|
2378
2546
|
}
|
|
2379
|
-
if (!writes.has(
|
|
2380
|
-
writes.set(
|
|
2547
|
+
if (!writes.has(path10)) {
|
|
2548
|
+
writes.set(path10, {
|
|
2381
2549
|
lastChange: now,
|
|
2382
2550
|
cancelWait: () => {
|
|
2383
|
-
writes.delete(
|
|
2551
|
+
writes.delete(path10);
|
|
2384
2552
|
clearTimeout(timeoutHandler);
|
|
2385
2553
|
return event;
|
|
2386
2554
|
}
|
|
@@ -2391,8 +2559,8 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2391
2559
|
/**
|
|
2392
2560
|
* Determines whether user has asked to ignore this path.
|
|
2393
2561
|
*/
|
|
2394
|
-
_isIgnored(
|
|
2395
|
-
if (this.options.atomic && DOT_RE.test(
|
|
2562
|
+
_isIgnored(path10, stats) {
|
|
2563
|
+
if (this.options.atomic && DOT_RE.test(path10))
|
|
2396
2564
|
return true;
|
|
2397
2565
|
if (!this._userIgnored) {
|
|
2398
2566
|
const { cwd } = this.options;
|
|
@@ -2402,17 +2570,17 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2402
2570
|
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
2403
2571
|
this._userIgnored = anymatch(list, void 0);
|
|
2404
2572
|
}
|
|
2405
|
-
return this._userIgnored(
|
|
2573
|
+
return this._userIgnored(path10, stats);
|
|
2406
2574
|
}
|
|
2407
|
-
_isntIgnored(
|
|
2408
|
-
return !this._isIgnored(
|
|
2575
|
+
_isntIgnored(path10, stat9) {
|
|
2576
|
+
return !this._isIgnored(path10, stat9);
|
|
2409
2577
|
}
|
|
2410
2578
|
/**
|
|
2411
2579
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
2412
2580
|
* @param path file or directory pattern being watched
|
|
2413
2581
|
*/
|
|
2414
|
-
_getWatchHelpers(
|
|
2415
|
-
return new WatchHelper(
|
|
2582
|
+
_getWatchHelpers(path10) {
|
|
2583
|
+
return new WatchHelper(path10, this.options.followSymlinks, this);
|
|
2416
2584
|
}
|
|
2417
2585
|
// Directory helpers
|
|
2418
2586
|
// -----------------
|
|
@@ -2444,63 +2612,63 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2444
2612
|
* @param item base path of item/directory
|
|
2445
2613
|
*/
|
|
2446
2614
|
_remove(directory, item, isDirectory) {
|
|
2447
|
-
const
|
|
2448
|
-
const fullPath = sp2.resolve(
|
|
2449
|
-
isDirectory = isDirectory != null ? isDirectory : this._watched.has(
|
|
2450
|
-
if (!this._throttle("remove",
|
|
2615
|
+
const path10 = sp2.join(directory, item);
|
|
2616
|
+
const fullPath = sp2.resolve(path10);
|
|
2617
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path10) || this._watched.has(fullPath);
|
|
2618
|
+
if (!this._throttle("remove", path10, 100))
|
|
2451
2619
|
return;
|
|
2452
2620
|
if (!isDirectory && this._watched.size === 1) {
|
|
2453
2621
|
this.add(directory, item, true);
|
|
2454
2622
|
}
|
|
2455
|
-
const wp = this._getWatchedDir(
|
|
2623
|
+
const wp = this._getWatchedDir(path10);
|
|
2456
2624
|
const nestedDirectoryChildren = wp.getChildren();
|
|
2457
|
-
nestedDirectoryChildren.forEach((nested) => this._remove(
|
|
2625
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path10, nested));
|
|
2458
2626
|
const parent = this._getWatchedDir(directory);
|
|
2459
2627
|
const wasTracked = parent.has(item);
|
|
2460
2628
|
parent.remove(item);
|
|
2461
2629
|
if (this._symlinkPaths.has(fullPath)) {
|
|
2462
2630
|
this._symlinkPaths.delete(fullPath);
|
|
2463
2631
|
}
|
|
2464
|
-
let relPath =
|
|
2632
|
+
let relPath = path10;
|
|
2465
2633
|
if (this.options.cwd)
|
|
2466
|
-
relPath = sp2.relative(this.options.cwd,
|
|
2634
|
+
relPath = sp2.relative(this.options.cwd, path10);
|
|
2467
2635
|
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
2468
2636
|
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
2469
2637
|
if (event === EVENTS.ADD)
|
|
2470
2638
|
return;
|
|
2471
2639
|
}
|
|
2472
|
-
this._watched.delete(
|
|
2640
|
+
this._watched.delete(path10);
|
|
2473
2641
|
this._watched.delete(fullPath);
|
|
2474
2642
|
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
2475
|
-
if (wasTracked && !this._isIgnored(
|
|
2476
|
-
this._emit(eventName,
|
|
2477
|
-
this._closePath(
|
|
2643
|
+
if (wasTracked && !this._isIgnored(path10))
|
|
2644
|
+
this._emit(eventName, path10);
|
|
2645
|
+
this._closePath(path10);
|
|
2478
2646
|
}
|
|
2479
2647
|
/**
|
|
2480
2648
|
* Closes all watchers for a path
|
|
2481
2649
|
*/
|
|
2482
|
-
_closePath(
|
|
2483
|
-
this._closeFile(
|
|
2484
|
-
const dir = sp2.dirname(
|
|
2485
|
-
this._getWatchedDir(dir).remove(sp2.basename(
|
|
2650
|
+
_closePath(path10) {
|
|
2651
|
+
this._closeFile(path10);
|
|
2652
|
+
const dir = sp2.dirname(path10);
|
|
2653
|
+
this._getWatchedDir(dir).remove(sp2.basename(path10));
|
|
2486
2654
|
}
|
|
2487
2655
|
/**
|
|
2488
2656
|
* Closes only file-specific watchers
|
|
2489
2657
|
*/
|
|
2490
|
-
_closeFile(
|
|
2491
|
-
const closers = this._closers.get(
|
|
2658
|
+
_closeFile(path10) {
|
|
2659
|
+
const closers = this._closers.get(path10);
|
|
2492
2660
|
if (!closers)
|
|
2493
2661
|
return;
|
|
2494
2662
|
closers.forEach((closer) => closer());
|
|
2495
|
-
this._closers.delete(
|
|
2663
|
+
this._closers.delete(path10);
|
|
2496
2664
|
}
|
|
2497
|
-
_addPathCloser(
|
|
2665
|
+
_addPathCloser(path10, closer) {
|
|
2498
2666
|
if (!closer)
|
|
2499
2667
|
return;
|
|
2500
|
-
let list = this._closers.get(
|
|
2668
|
+
let list = this._closers.get(path10);
|
|
2501
2669
|
if (!list) {
|
|
2502
2670
|
list = [];
|
|
2503
|
-
this._closers.set(
|
|
2671
|
+
this._closers.set(path10, list);
|
|
2504
2672
|
}
|
|
2505
2673
|
list.push(closer);
|
|
2506
2674
|
}
|
|
@@ -2531,49 +2699,243 @@ var chokidar_default = { watch, FSWatcher };
|
|
|
2531
2699
|
|
|
2532
2700
|
// src/core/watch.ts
|
|
2533
2701
|
import { $ as $7 } from "execa";
|
|
2702
|
+
import { build as esbuild2 } from "esbuild";
|
|
2703
|
+
import { findWorkspacesRoot as findWorkspacesRoot2 } from "find-workspaces";
|
|
2704
|
+
import chalk10 from "chalk";
|
|
2534
2705
|
var watchCommand = new Command10("watch").description(
|
|
2535
|
-
"Watches the src directory and rebuilds
|
|
2536
|
-
).action(() => {
|
|
2706
|
+
"Watches the src directory and incrementally rebuilds files on changes (Vite-style)"
|
|
2707
|
+
).action(async () => {
|
|
2537
2708
|
const cwd = process.cwd();
|
|
2538
|
-
const srcDir =
|
|
2539
|
-
|
|
2540
|
-
let
|
|
2541
|
-
let
|
|
2542
|
-
const
|
|
2543
|
-
if (
|
|
2544
|
-
|
|
2545
|
-
|
|
2709
|
+
const srcDir = path9.join(cwd, "src");
|
|
2710
|
+
const pkgJsonPath = path9.join(cwd, "package.json");
|
|
2711
|
+
let watcher = null;
|
|
2712
|
+
let configWatcher = null;
|
|
2713
|
+
const startWatcher = async (isReload = false) => {
|
|
2714
|
+
if (watcher) {
|
|
2715
|
+
await watcher.close();
|
|
2716
|
+
}
|
|
2717
|
+
const isVerbose = process.env.SSE_BUILD_VERBOSE === "true";
|
|
2718
|
+
if (isReload) {
|
|
2719
|
+
console.log(
|
|
2720
|
+
chalk10.cyan(`
|
|
2721
|
+
\u{1F504} Configuration change detected. Reloading...`)
|
|
2722
|
+
);
|
|
2546
2723
|
}
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2724
|
+
const packageJsonContent = await fs9.readFile(pkgJsonPath, "utf8");
|
|
2725
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
2726
|
+
const buildDirBase = packageJson.publishConfig?.directory || "build";
|
|
2727
|
+
const buildDir = path9.join(cwd, buildDirBase);
|
|
2728
|
+
const fileConfig = await loadConfig();
|
|
2729
|
+
const bundles = fileConfig.bundle || ["esm", "cjs"];
|
|
2730
|
+
const isFlat = fileConfig.flat ?? false;
|
|
2731
|
+
const packageType = packageJson.type === "module" ? "module" : "commonjs";
|
|
2732
|
+
const isEsbuild = !!fileConfig.esbuild;
|
|
2733
|
+
const builder = isEsbuild ? "esbuild" : "babel";
|
|
2734
|
+
const workspaceDir = await findWorkspacesRoot2(cwd);
|
|
2735
|
+
const rootDir = workspaceDir ? workspaceDir.location : cwd;
|
|
2736
|
+
const pm = getPackageManager();
|
|
2737
|
+
const pmExec = getPmExec();
|
|
2738
|
+
let babelRuntimeVersion = packageJson.dependencies?.["@babel/runtime"];
|
|
2739
|
+
const reactVersion = packageJson.peerDependencies?.react || "latest";
|
|
2740
|
+
console.log(
|
|
2741
|
+
chalk10.blue(`\u{1F440} Watching for changes (Builder: ${builder})...`)
|
|
2742
|
+
);
|
|
2550
2743
|
try {
|
|
2551
|
-
await $7({
|
|
2552
|
-
|
|
2744
|
+
await $7({
|
|
2745
|
+
stdio: "inherit",
|
|
2746
|
+
preferLocal: true
|
|
2747
|
+
})`${pmExec} sse-tools build`;
|
|
2553
2748
|
} catch (err) {
|
|
2554
|
-
console.error(
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
buildQueued = false;
|
|
2559
|
-
runBuild();
|
|
2560
|
-
}
|
|
2749
|
+
console.error(
|
|
2750
|
+
chalk10.red(`\u274C Initial build failed. Waiting for changes...
|
|
2751
|
+
`)
|
|
2752
|
+
);
|
|
2561
2753
|
}
|
|
2754
|
+
const buildFile = async (filePath) => {
|
|
2755
|
+
const relativePath = path9.relative(srcDir, filePath);
|
|
2756
|
+
const minify = fileConfig.minify ?? false;
|
|
2757
|
+
if (builder === "esbuild") {
|
|
2758
|
+
if (isVerbose)
|
|
2759
|
+
console.log(
|
|
2760
|
+
chalk10.gray(
|
|
2761
|
+
`\u{1F680} [esbuild] Incremental rebuild triggered by ${relativePath}...`
|
|
2762
|
+
)
|
|
2763
|
+
);
|
|
2764
|
+
const esbuildConfig = fileConfig.esbuild;
|
|
2765
|
+
const entryPoints = typeof esbuildConfig.entry === "string" ? [esbuildConfig.entry] : esbuildConfig.entry;
|
|
2766
|
+
try {
|
|
2767
|
+
await Promise.all(
|
|
2768
|
+
bundles.map(async (bundle) => {
|
|
2769
|
+
const outExtension = getOutExtension(bundle, {
|
|
2770
|
+
isFlat,
|
|
2771
|
+
packageType
|
|
2772
|
+
});
|
|
2773
|
+
const relativeOutDir = isFlat ? "." : bundle === "esm" ? "esm" : ".";
|
|
2774
|
+
const outputDir = path9.join(buildDir, relativeOutDir);
|
|
2775
|
+
await esbuild2({
|
|
2776
|
+
entryPoints,
|
|
2777
|
+
bundle: true,
|
|
2778
|
+
outdir: outputDir,
|
|
2779
|
+
format: bundle === "esm" ? "esm" : "cjs",
|
|
2780
|
+
target: esbuildConfig.target || ["es2020", "node14"],
|
|
2781
|
+
minify,
|
|
2782
|
+
outExtension: { ".js": outExtension },
|
|
2783
|
+
external: [
|
|
2784
|
+
...Object.keys(packageJson.dependencies || {}),
|
|
2785
|
+
...Object.keys(packageJson.peerDependencies || {}),
|
|
2786
|
+
...esbuildConfig.external || []
|
|
2787
|
+
]
|
|
2788
|
+
});
|
|
2789
|
+
})
|
|
2790
|
+
);
|
|
2791
|
+
if (isVerbose)
|
|
2792
|
+
console.log(chalk10.green(`\u2705 [esbuild] Rebuild complete.`));
|
|
2793
|
+
} catch (err) {
|
|
2794
|
+
console.error(
|
|
2795
|
+
chalk10.red(`\u274C [esbuild] Rebuild failed:`),
|
|
2796
|
+
err.message
|
|
2797
|
+
);
|
|
2798
|
+
}
|
|
2799
|
+
} else {
|
|
2800
|
+
const ext = path9.extname(filePath);
|
|
2801
|
+
if (![".js", ".jsx", ".ts", ".tsx"].includes(ext) || filePath.endsWith(".d.ts"))
|
|
2802
|
+
return;
|
|
2803
|
+
let babelConfigFile = path9.join(rootDir, "babel.config.js");
|
|
2804
|
+
if (!await fs9.stat(babelConfigFile).then(() => true).catch(() => false)) {
|
|
2805
|
+
babelConfigFile = path9.join(rootDir, "babel.config.mjs");
|
|
2806
|
+
}
|
|
2807
|
+
await Promise.all(
|
|
2808
|
+
bundles.map(async (bundle) => {
|
|
2809
|
+
const outExtension = getOutExtension(bundle, {
|
|
2810
|
+
isFlat,
|
|
2811
|
+
packageType
|
|
2812
|
+
});
|
|
2813
|
+
const relativeOutDir = isFlat ? "." : bundle === "esm" ? "esm" : ".";
|
|
2814
|
+
const outputDir = path9.join(buildDir, relativeOutDir);
|
|
2815
|
+
const outFilePath = path9.join(
|
|
2816
|
+
outputDir,
|
|
2817
|
+
relativePath.replace(new RegExp(`\\${ext}$`), outExtension)
|
|
2818
|
+
);
|
|
2819
|
+
await fs9.mkdir(path9.dirname(outFilePath), { recursive: true });
|
|
2820
|
+
const env = {
|
|
2821
|
+
NODE_ENV: "production",
|
|
2822
|
+
BABEL_ENV: bundle === "esm" ? "stable" : "node",
|
|
2823
|
+
SSE_OUT_FILE_EXTENSION: outExtension,
|
|
2824
|
+
SSE_MINIFY: minify ? "true" : void 0,
|
|
2825
|
+
SSE_BABEL_RUNTIME_VERSION: babelRuntimeVersion,
|
|
2826
|
+
...getVersionEnvVariables(packageJson.version)
|
|
2827
|
+
};
|
|
2828
|
+
await $7({
|
|
2829
|
+
stdio: "pipe",
|
|
2830
|
+
preferLocal: true,
|
|
2831
|
+
env: { ...process.env, ...env }
|
|
2832
|
+
})`babel --config-file ${babelConfigFile} --extensions .js,.jsx,.ts,.tsx ${filePath} --out-file ${outFilePath}`;
|
|
2833
|
+
})
|
|
2834
|
+
);
|
|
2835
|
+
if (isVerbose)
|
|
2836
|
+
console.log(chalk10.green(`\u2705 [babel] Updated ${relativePath}`));
|
|
2837
|
+
}
|
|
2838
|
+
};
|
|
2839
|
+
const updateExports = async () => {
|
|
2840
|
+
try {
|
|
2841
|
+
const freshPkg = JSON.parse(
|
|
2842
|
+
await fs9.readFile(pkgJsonPath, "utf8")
|
|
2843
|
+
);
|
|
2844
|
+
const relativeOutDirs = !isFlat ? { cjs: ".", esm: "esm" } : { cjs: ".", esm: "." };
|
|
2845
|
+
await writePackageJson({
|
|
2846
|
+
cwd,
|
|
2847
|
+
packageJson: freshPkg,
|
|
2848
|
+
bundles: bundles.map((type) => ({
|
|
2849
|
+
type,
|
|
2850
|
+
dir: relativeOutDirs[type]
|
|
2851
|
+
})),
|
|
2852
|
+
outputDir: buildDir,
|
|
2853
|
+
addTypes: fileConfig.buildTypes ?? true,
|
|
2854
|
+
isFlat,
|
|
2855
|
+
packageType,
|
|
2856
|
+
exportExtensions: fileConfig.exportExtensions
|
|
2857
|
+
});
|
|
2858
|
+
} catch (e) {
|
|
2859
|
+
console.error(chalk10.red(`\u274C Failed to update exports: ${e.message}`));
|
|
2860
|
+
}
|
|
2861
|
+
};
|
|
2862
|
+
let exportTimeout;
|
|
2863
|
+
const debouncedUpdateExports = () => {
|
|
2864
|
+
clearTimeout(exportTimeout);
|
|
2865
|
+
exportTimeout = setTimeout(() => updateExports(), 150);
|
|
2866
|
+
};
|
|
2867
|
+
watcher = chokidar_default.watch(srcDir, {
|
|
2868
|
+
ignored: /(^|[\/\\])\../,
|
|
2869
|
+
persistent: true,
|
|
2870
|
+
ignoreInitial: true
|
|
2871
|
+
});
|
|
2872
|
+
watcher.on("change", async (filePath) => await buildFile(filePath)).on("add", async (filePath) => {
|
|
2873
|
+
await buildFile(filePath);
|
|
2874
|
+
debouncedUpdateExports();
|
|
2875
|
+
}).on("unlink", async (filePath) => {
|
|
2876
|
+
const relativePath = path9.relative(srcDir, filePath);
|
|
2877
|
+
const ext = path9.extname(filePath);
|
|
2878
|
+
for (const bundle of bundles) {
|
|
2879
|
+
const outExtension = getOutExtension(bundle, {
|
|
2880
|
+
isFlat,
|
|
2881
|
+
packageType,
|
|
2882
|
+
isType: false
|
|
2883
|
+
});
|
|
2884
|
+
const relativeOutDir = isFlat ? "." : bundle === "esm" ? "esm" : ".";
|
|
2885
|
+
const outputDir = path9.join(buildDir, relativeOutDir);
|
|
2886
|
+
const outRelativePath = relativePath.replace(
|
|
2887
|
+
new RegExp(`\\${ext}$`),
|
|
2888
|
+
outExtension
|
|
2889
|
+
);
|
|
2890
|
+
await fs9.rm(path9.join(outputDir, outRelativePath), { force: true }).catch(() => {
|
|
2891
|
+
});
|
|
2892
|
+
}
|
|
2893
|
+
debouncedUpdateExports();
|
|
2894
|
+
}).on("unlinkDir", async (dirPath) => {
|
|
2895
|
+
const relativePath = path9.relative(srcDir, dirPath);
|
|
2896
|
+
for (const bundle of bundles) {
|
|
2897
|
+
const relativeOutDir = isFlat ? "." : bundle === "esm" ? "esm" : ".";
|
|
2898
|
+
await fs9.rm(path9.join(buildDir, relativeOutDir, relativePath), {
|
|
2899
|
+
recursive: true,
|
|
2900
|
+
force: true
|
|
2901
|
+
}).catch(() => {
|
|
2902
|
+
});
|
|
2903
|
+
}
|
|
2904
|
+
debouncedUpdateExports();
|
|
2905
|
+
});
|
|
2562
2906
|
};
|
|
2563
|
-
const
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2907
|
+
const configFiles = [
|
|
2908
|
+
"sse.config.ts",
|
|
2909
|
+
"sse.config.js",
|
|
2910
|
+
"sse.config.mjs",
|
|
2911
|
+
"sse.config.cjs",
|
|
2912
|
+
"sse.config.mts",
|
|
2913
|
+
"sse.config.cts",
|
|
2914
|
+
"sse.config.json",
|
|
2915
|
+
"package.json"
|
|
2916
|
+
];
|
|
2917
|
+
configWatcher = chokidar_default.watch(
|
|
2918
|
+
configFiles.map((f) => path9.join(cwd, f)),
|
|
2919
|
+
{
|
|
2920
|
+
persistent: true,
|
|
2921
|
+
ignoreInitial: true
|
|
2922
|
+
}
|
|
2923
|
+
);
|
|
2924
|
+
configWatcher.on("change", () => startWatcher(true));
|
|
2925
|
+
await startWatcher();
|
|
2571
2926
|
});
|
|
2572
2927
|
|
|
2573
2928
|
// src/cli.ts
|
|
2574
2929
|
async function main() {
|
|
2575
2930
|
const program = new Command11();
|
|
2576
|
-
program.name("sse-tools").description(
|
|
2931
|
+
program.name("sse-tools").description(
|
|
2932
|
+
chalk11.cyan("CLI utilities for managing and building SSE packages")
|
|
2933
|
+
).version("1.0.0").option("-v, --verbose", "Enable verbose logging across all commands");
|
|
2934
|
+
program.hook("preAction", (thisCommand) => {
|
|
2935
|
+
if (thisCommand.opts().verbose) {
|
|
2936
|
+
process.env.SSE_BUILD_VERBOSE = "true";
|
|
2937
|
+
}
|
|
2938
|
+
});
|
|
2577
2939
|
program.addCommand(buildCommand);
|
|
2578
2940
|
program.addCommand(publishCommand);
|
|
2579
2941
|
program.addCommand(cleanCommand);
|