@plumeria/compiler 0.25.2 → 0.25.3
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/extract.js +24 -23
- package/dist/index.js +9 -15
- package/package.json +3 -3
package/dist/extract.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generatedTsMap = void 0;
|
|
7
7
|
exports.extractTSFile = extractTSFile;
|
|
8
|
-
exports.restoreAllOriginals = restoreAllOriginals;
|
|
9
8
|
exports.extractVueAndSvelte = extractVueAndSvelte;
|
|
10
9
|
const core_1 = require("@swc/core");
|
|
11
10
|
const promises_1 = require("fs/promises");
|
|
@@ -159,8 +158,11 @@ function expressionToString(expr) {
|
|
|
159
158
|
console.warn(`css.props: Argument unsupported ${expr.type}: Use css.create instead.`);
|
|
160
159
|
return '';
|
|
161
160
|
}
|
|
162
|
-
async function extractCssProps(ast) {
|
|
161
|
+
async function extractCssProps(ast, code) {
|
|
163
162
|
const propsMatches = [];
|
|
163
|
+
if (code && !code.includes('css.props')) {
|
|
164
|
+
return propsMatches;
|
|
165
|
+
}
|
|
164
166
|
try {
|
|
165
167
|
await visit(ast, {
|
|
166
168
|
CallExpression: async (node) => {
|
|
@@ -350,7 +352,10 @@ async function extractImportDeclarations(ast) {
|
|
|
350
352
|
}
|
|
351
353
|
return importDeclarations.join('\n');
|
|
352
354
|
}
|
|
353
|
-
async function extractCssMethod(ast, methodName) {
|
|
355
|
+
async function extractCssMethod(ast, methodName, code) {
|
|
356
|
+
if (!code.includes(`css.${methodName}`)) {
|
|
357
|
+
return '';
|
|
358
|
+
}
|
|
354
359
|
const matches = [];
|
|
355
360
|
try {
|
|
356
361
|
for (const node of ast.body) {
|
|
@@ -410,7 +415,7 @@ async function extractVueAndSvelte(filePath) {
|
|
|
410
415
|
syntax: 'typescript',
|
|
411
416
|
tsx: true,
|
|
412
417
|
});
|
|
413
|
-
const propsFromScript = await extractCssProps(ast);
|
|
418
|
+
const propsFromScript = await extractCssProps(ast, code);
|
|
414
419
|
const propsFromTemplate = extractCssPropsFromTemplate(code);
|
|
415
420
|
const propsMatches = [...new Set([...propsFromScript, ...propsFromTemplate])];
|
|
416
421
|
const calls = propsMatches
|
|
@@ -419,11 +424,11 @@ async function extractVueAndSvelte(filePath) {
|
|
|
419
424
|
.join('\n');
|
|
420
425
|
const importSection = await extractImportDeclarations(ast);
|
|
421
426
|
const staticVariableSection = await extractStaticStringLiteralVariable(ast);
|
|
422
|
-
const cssCreateSection = await extractCssMethod(ast, 'create');
|
|
423
|
-
const cssKeyframesSection = await extractCssMethod(ast, 'keyframes');
|
|
424
|
-
const cssViewTransitionSection = await extractCssMethod(ast, 'viewTransition');
|
|
425
|
-
const cssDefineConstsSection = await extractCssMethod(ast, 'defineConsts');
|
|
426
|
-
const cssDefineTokensSection = await extractCssMethod(ast, 'defineTokens');
|
|
427
|
+
const cssCreateSection = await extractCssMethod(ast, 'create', code);
|
|
428
|
+
const cssKeyframesSection = await extractCssMethod(ast, 'keyframes', code);
|
|
429
|
+
const cssViewTransitionSection = await extractCssMethod(ast, 'viewTransition', code);
|
|
430
|
+
const cssDefineConstsSection = await extractCssMethod(ast, 'defineConsts', code);
|
|
431
|
+
const cssDefineTokensSection = await extractCssMethod(ast, 'defineTokens', code);
|
|
427
432
|
let finalCode = '';
|
|
428
433
|
if (importSection)
|
|
429
434
|
finalCode += importSection + '\n';
|
|
@@ -442,7 +447,7 @@ async function extractVueAndSvelte(filePath) {
|
|
|
442
447
|
if (calls)
|
|
443
448
|
finalCode += calls + '\n';
|
|
444
449
|
generatedTsMap.set(filePath, finalCode);
|
|
445
|
-
return
|
|
450
|
+
return filePath;
|
|
446
451
|
}
|
|
447
452
|
async function extractTSFile(filePath) {
|
|
448
453
|
const code = await (0, promises_1.readFile)(filePath, 'utf8');
|
|
@@ -452,12 +457,12 @@ async function extractTSFile(filePath) {
|
|
|
452
457
|
});
|
|
453
458
|
const importSection = await extractImportDeclarations(ast);
|
|
454
459
|
const staticVariableSection = await extractStaticStringLiteralVariable(ast);
|
|
455
|
-
const cssCreateSection = await extractCssMethod(ast, 'create');
|
|
456
|
-
const cssKeyframesSection = await extractCssMethod(ast, 'keyframes');
|
|
457
|
-
const cssViewTransitionSection = await extractCssMethod(ast, 'viewTransition');
|
|
458
|
-
const cssDefineConstsSection = await extractCssMethod(ast, 'defineConsts');
|
|
459
|
-
const cssDefineTokensSection = await extractCssMethod(ast, 'defineTokens');
|
|
460
|
-
const propsMatches = await extractCssProps(ast);
|
|
460
|
+
const cssCreateSection = await extractCssMethod(ast, 'create', code);
|
|
461
|
+
const cssKeyframesSection = await extractCssMethod(ast, 'keyframes', code);
|
|
462
|
+
const cssViewTransitionSection = await extractCssMethod(ast, 'viewTransition', code);
|
|
463
|
+
const cssDefineConstsSection = await extractCssMethod(ast, 'defineConsts', code);
|
|
464
|
+
const cssDefineTokensSection = await extractCssMethod(ast, 'defineTokens', code);
|
|
465
|
+
const propsMatches = await extractCssProps(ast, code);
|
|
461
466
|
const calls = propsMatches
|
|
462
467
|
.filter(Boolean)
|
|
463
468
|
.map((call) => `${call};`)
|
|
@@ -478,20 +483,16 @@ async function extractTSFile(filePath) {
|
|
|
478
483
|
if (cssCreateSection)
|
|
479
484
|
finalCode += cssCreateSection + '\n';
|
|
480
485
|
finalCode += calls;
|
|
481
|
-
const tempFilePath = filePath.replace(path_1.default.extname(filePath), '-temp.ts');
|
|
482
486
|
generatedTsMap.set(filePath, finalCode);
|
|
483
|
-
return
|
|
484
|
-
}
|
|
485
|
-
async function restoreAllOriginals() {
|
|
486
|
-
generatedTsMap.clear();
|
|
487
|
+
return filePath;
|
|
487
488
|
}
|
|
488
489
|
process.on('uncaughtException', async (error) => {
|
|
489
490
|
console.error('Uncaught Exception:', error);
|
|
490
|
-
|
|
491
|
+
generatedTsMap.clear();
|
|
491
492
|
process.exit(1);
|
|
492
493
|
});
|
|
493
494
|
process.on('unhandledRejection', async (reason, promise) => {
|
|
494
495
|
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
495
|
-
|
|
496
|
+
generatedTsMap.clear();
|
|
496
497
|
process.exit(1);
|
|
497
498
|
});
|
package/dist/index.js
CHANGED
|
@@ -198,43 +198,37 @@ async function main() {
|
|
|
198
198
|
files.push(entry);
|
|
199
199
|
}
|
|
200
200
|
const projectName = path_1.default.basename(projectRoot);
|
|
201
|
-
const tempToOriginalMap = new Map();
|
|
202
201
|
const filesSupportExtensions = await Promise.all(files.map(async (file) => {
|
|
203
202
|
const ext = path_1.default.extname(file);
|
|
204
|
-
let tempFile;
|
|
205
203
|
if (ext === '.vue' || ext === '.svelte') {
|
|
206
|
-
|
|
204
|
+
return await (0, extract_1.extractVueAndSvelte)(file);
|
|
207
205
|
}
|
|
208
206
|
else {
|
|
209
|
-
|
|
207
|
+
return await (0, extract_1.extractTSFile)(file);
|
|
210
208
|
}
|
|
211
|
-
tempToOriginalMap.set(tempFile, file);
|
|
212
|
-
return tempFile;
|
|
213
209
|
}));
|
|
214
210
|
const styleFiles = await Promise.all(filesSupportExtensions.map(async (file) => {
|
|
215
|
-
const
|
|
216
|
-
const code = extract_1.generatedTsMap.get(originalFile);
|
|
211
|
+
const code = extract_1.generatedTsMap.get(file);
|
|
217
212
|
const isCssFile = code ? await isCSS(code, file) : false;
|
|
218
213
|
return isCssFile ? file : null;
|
|
219
214
|
}))
|
|
220
215
|
.then((results) => results.filter(Boolean))
|
|
221
216
|
.then((results) => results.sort());
|
|
222
217
|
for (const file of styleFiles) {
|
|
223
|
-
const
|
|
224
|
-
const code = extract_1.generatedTsMap.get(originalFile);
|
|
218
|
+
const code = extract_1.generatedTsMap.get(file);
|
|
225
219
|
if (code) {
|
|
226
|
-
|
|
227
|
-
|
|
220
|
+
const ext = path_1.default.extname(file);
|
|
221
|
+
const tsPath = ext === '.vue' || ext === '.svelte' ? file.replace(ext, '.ts') : file;
|
|
222
|
+
await (0, execute_1.executeCode)(code, { filePath: tsPath });
|
|
228
223
|
if (process.argv.includes('--paths')) {
|
|
229
|
-
console.log(`✅: ${projectName}/${path_1.default.relative(projectRoot,
|
|
224
|
+
console.log(`✅: ${projectName}/${path_1.default.relative(projectRoot, file)}`);
|
|
230
225
|
}
|
|
231
|
-
await (0, promises_1.unlink)(file);
|
|
232
226
|
}
|
|
233
227
|
}
|
|
234
228
|
await (0, processors_1.buildGlobal)(coreFilePath);
|
|
235
229
|
await (0, processors_1.buildProps)(coreFilePath);
|
|
236
230
|
await optimizeCSS();
|
|
237
|
-
|
|
231
|
+
extract_1.generatedTsMap.clear();
|
|
238
232
|
if (process.argv.includes('--stats')) {
|
|
239
233
|
const endTime = performance.now();
|
|
240
234
|
const buildTime = (endTime - startTime) / 1000;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.3",
|
|
4
4
|
"description": "Plumeria Rust-based compiler",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"css": "./bin/css.js"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@swc/core": "1.15.
|
|
19
|
+
"@swc/core": "1.15.1",
|
|
20
20
|
"find-up": "^8.0.0",
|
|
21
21
|
"lightningcss": "^1.30.2",
|
|
22
22
|
"postcss": "^8.5.6",
|
|
23
23
|
"postcss-combine-media-query": "^2.1.0",
|
|
24
|
-
"rscute": "^1.
|
|
24
|
+
"rscute": "^1.1.1"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|