@lark-apaas/fullstack-cli 1.1.63-alpha.20260826101330 → 1.1.63-alpha.20260826175639
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 +120 -0
package/package.json
CHANGED
|
@@ -42,6 +42,115 @@ 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 || !rootDir) {
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let removed = 0;
|
|
97
|
+
const pendingDirectories = [sourceRoot];
|
|
98
|
+
while (pendingDirectories.length > 0) {
|
|
99
|
+
const currentDirectory = pendingDirectories.pop();
|
|
100
|
+
for (const entry of fs.readdirSync(currentDirectory, {
|
|
101
|
+
withFileTypes: true,
|
|
102
|
+
})) {
|
|
103
|
+
const sourcePath = path.join(currentDirectory, entry.name);
|
|
104
|
+
if (entry.isDirectory()) {
|
|
105
|
+
pendingDirectories.push(sourcePath);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (!entry.isFile() || entry.name.endsWith('.d.ts')) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const sourceExtension = ['.tsx', '.mts', '.cts', '.ts'].find(extension =>
|
|
113
|
+
entry.name.endsWith(extension)
|
|
114
|
+
);
|
|
115
|
+
if (!sourceExtension) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const relativeSourcePath = path.relative(rootDir, sourcePath);
|
|
119
|
+
if (
|
|
120
|
+
relativeSourcePath === '..' ||
|
|
121
|
+
relativeSourcePath.startsWith(`..${path.sep}`) ||
|
|
122
|
+
path.isAbsolute(relativeSourcePath)
|
|
123
|
+
) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const outputExtension =
|
|
128
|
+
sourceExtension === '.mts'
|
|
129
|
+
? '.mjs'
|
|
130
|
+
: sourceExtension === '.cts'
|
|
131
|
+
? '.cjs'
|
|
132
|
+
: '.js';
|
|
133
|
+
const outputBasePath = path.join(
|
|
134
|
+
outDir,
|
|
135
|
+
relativeSourcePath.slice(0, -sourceExtension.length)
|
|
136
|
+
);
|
|
137
|
+
for (const suffix of [
|
|
138
|
+
outputExtension,
|
|
139
|
+
`${outputExtension}.map`,
|
|
140
|
+
'.d.ts',
|
|
141
|
+
'.d.ts.map',
|
|
142
|
+
]) {
|
|
143
|
+
const outputPath = `${outputBasePath}${suffix}`;
|
|
144
|
+
if (fs.existsSync(outputPath)) {
|
|
145
|
+
fs.rmSync(outputPath, { force: true });
|
|
146
|
+
removed += 1;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return removed;
|
|
152
|
+
}
|
|
153
|
+
|
|
45
154
|
function startNest(projectRoot, nestArgs) {
|
|
46
155
|
const child = spawn(
|
|
47
156
|
process.execPath,
|
|
@@ -118,6 +227,16 @@ function main() {
|
|
|
118
227
|
return;
|
|
119
228
|
}
|
|
120
229
|
|
|
230
|
+
try {
|
|
231
|
+
const removed = cleanStaleSwcOutputs(projectRoot);
|
|
232
|
+
console.log(
|
|
233
|
+
`[miaoda:nest-compiler] MIAODA_NEST_SWC_CLEANUP removed=${removed}`
|
|
234
|
+
);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
console.error(
|
|
237
|
+
`[miaoda:nest-compiler] MIAODA_NEST_SWC_CLEANUP_FAILED message=${JSON.stringify(error.message)}`
|
|
238
|
+
);
|
|
239
|
+
}
|
|
121
240
|
console.log('[miaoda:nest-compiler] MIAODA_NEST_COMPILER=swc');
|
|
122
241
|
startNest(projectRoot, [
|
|
123
242
|
'start',
|
|
@@ -134,6 +253,7 @@ if (require.main === module) {
|
|
|
134
253
|
}
|
|
135
254
|
|
|
136
255
|
module.exports = {
|
|
256
|
+
cleanStaleSwcOutputs,
|
|
137
257
|
findMissingSwcDependency,
|
|
138
258
|
resolveBuilder,
|
|
139
259
|
};
|