@lark-apaas/fullstack-cli 1.1.63-alpha.20260826101330 → 1.1.63-alpha.20260826182714
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/package.json +1 -1
- package/templates/scripts/dev-server.js +126 -0
package/package.json
CHANGED
|
@@ -42,6 +42,121 @@ function resolveNestEntrypoint(projectRoot) {
|
|
|
42
42
|
return require.resolve('@nestjs/cli/bin/nest.js', { paths: [projectRoot] });
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
function resolveInsideProject(projectRoot, configuredPath) {
|
|
46
|
+
const resolvedPath = path.resolve(projectRoot, configuredPath);
|
|
47
|
+
const relativePath = path.relative(projectRoot, resolvedPath);
|
|
48
|
+
if (
|
|
49
|
+
relativePath === '..' ||
|
|
50
|
+
relativePath.startsWith(`..${path.sep}`) ||
|
|
51
|
+
path.isAbsolute(relativePath)
|
|
52
|
+
) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return resolvedPath;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readJsonStringProperty(filePath, propertyName, fallback) {
|
|
59
|
+
if (!fs.existsSync(filePath)) {
|
|
60
|
+
return fallback;
|
|
61
|
+
}
|
|
62
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
63
|
+
const match = content.match(
|
|
64
|
+
new RegExp(`"${propertyName}"\\s*:\\s*"([^"\\r\\n]+)"`)
|
|
65
|
+
);
|
|
66
|
+
return match?.[1] ?? fallback;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function cleanStaleSwcOutputs(projectRoot) {
|
|
70
|
+
const nestConfigPath = path.join(projectRoot, 'nest-cli.json');
|
|
71
|
+
const nestConfig = JSON.parse(fs.readFileSync(nestConfigPath, 'utf8'));
|
|
72
|
+
const sourceRootName =
|
|
73
|
+
typeof nestConfig.sourceRoot === 'string' ? nestConfig.sourceRoot : 'src';
|
|
74
|
+
const tsConfigName =
|
|
75
|
+
typeof nestConfig.compilerOptions?.tsConfigPath === 'string'
|
|
76
|
+
? nestConfig.compilerOptions.tsConfigPath
|
|
77
|
+
: 'tsconfig.json';
|
|
78
|
+
const tsConfigPath = resolveInsideProject(projectRoot, tsConfigName);
|
|
79
|
+
const sourceRoot = resolveInsideProject(projectRoot, sourceRootName);
|
|
80
|
+
if (!tsConfigPath || !sourceRoot || !fs.existsSync(sourceRoot)) {
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const outDirName = readJsonStringProperty(tsConfigPath, 'outDir', 'dist');
|
|
85
|
+
const rootDirName = readJsonStringProperty(
|
|
86
|
+
tsConfigPath,
|
|
87
|
+
'rootDir',
|
|
88
|
+
sourceRootName
|
|
89
|
+
);
|
|
90
|
+
const outDir = resolveInsideProject(projectRoot, outDirName);
|
|
91
|
+
const rootDir = resolveInsideProject(projectRoot, rootDirName);
|
|
92
|
+
if (!outDir) {
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
const emitRoots = [sourceRoot];
|
|
96
|
+
if (rootDir && rootDir !== sourceRoot) {
|
|
97
|
+
emitRoots.push(rootDir);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let removed = 0;
|
|
101
|
+
const pendingDirectories = [sourceRoot];
|
|
102
|
+
while (pendingDirectories.length > 0) {
|
|
103
|
+
const currentDirectory = pendingDirectories.pop();
|
|
104
|
+
for (const entry of fs.readdirSync(currentDirectory, {
|
|
105
|
+
withFileTypes: true,
|
|
106
|
+
})) {
|
|
107
|
+
const sourcePath = path.join(currentDirectory, entry.name);
|
|
108
|
+
if (entry.isDirectory()) {
|
|
109
|
+
pendingDirectories.push(sourcePath);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (!entry.isFile() || entry.name.endsWith('.d.ts')) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const sourceExtension = ['.tsx', '.mts', '.cts', '.ts'].find(extension =>
|
|
117
|
+
entry.name.endsWith(extension)
|
|
118
|
+
);
|
|
119
|
+
if (!sourceExtension) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const outputExtension =
|
|
123
|
+
sourceExtension === '.mts'
|
|
124
|
+
? '.mjs'
|
|
125
|
+
: sourceExtension === '.cts'
|
|
126
|
+
? '.cjs'
|
|
127
|
+
: '.js';
|
|
128
|
+
for (const emitRoot of emitRoots) {
|
|
129
|
+
const relativeSourcePath = path.relative(emitRoot, sourcePath);
|
|
130
|
+
if (
|
|
131
|
+
relativeSourcePath === '..' ||
|
|
132
|
+
relativeSourcePath.startsWith(`..${path.sep}`) ||
|
|
133
|
+
path.isAbsolute(relativeSourcePath)
|
|
134
|
+
) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const outputBasePath = path.join(
|
|
139
|
+
outDir,
|
|
140
|
+
relativeSourcePath.slice(0, -sourceExtension.length)
|
|
141
|
+
);
|
|
142
|
+
for (const suffix of [
|
|
143
|
+
outputExtension,
|
|
144
|
+
`${outputExtension}.map`,
|
|
145
|
+
'.d.ts',
|
|
146
|
+
'.d.ts.map',
|
|
147
|
+
]) {
|
|
148
|
+
const outputPath = `${outputBasePath}${suffix}`;
|
|
149
|
+
if (fs.existsSync(outputPath)) {
|
|
150
|
+
fs.rmSync(outputPath, { force: true });
|
|
151
|
+
removed += 1;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return removed;
|
|
158
|
+
}
|
|
159
|
+
|
|
45
160
|
function startNest(projectRoot, nestArgs) {
|
|
46
161
|
const child = spawn(
|
|
47
162
|
process.execPath,
|
|
@@ -118,6 +233,16 @@ function main() {
|
|
|
118
233
|
return;
|
|
119
234
|
}
|
|
120
235
|
|
|
236
|
+
try {
|
|
237
|
+
const removed = cleanStaleSwcOutputs(projectRoot);
|
|
238
|
+
console.log(
|
|
239
|
+
`[miaoda:nest-compiler] MIAODA_NEST_SWC_CLEANUP removed=${removed}`
|
|
240
|
+
);
|
|
241
|
+
} catch (error) {
|
|
242
|
+
console.error(
|
|
243
|
+
`[miaoda:nest-compiler] MIAODA_NEST_SWC_CLEANUP_FAILED message=${JSON.stringify(error.message)}`
|
|
244
|
+
);
|
|
245
|
+
}
|
|
121
246
|
console.log('[miaoda:nest-compiler] MIAODA_NEST_COMPILER=swc');
|
|
122
247
|
startNest(projectRoot, [
|
|
123
248
|
'start',
|
|
@@ -134,6 +259,7 @@ if (require.main === module) {
|
|
|
134
259
|
}
|
|
135
260
|
|
|
136
261
|
module.exports = {
|
|
262
|
+
cleanStaleSwcOutputs,
|
|
137
263
|
findMissingSwcDependency,
|
|
138
264
|
resolveBuilder,
|
|
139
265
|
};
|