@plumeria/compiler 0.25.1 → 0.25.2

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.
Files changed (3) hide show
  1. package/dist/extract.js +48 -58
  2. package/dist/index.js +173 -152
  3. package/package.json +2 -2
package/dist/extract.js CHANGED
@@ -8,7 +8,7 @@ exports.extractTSFile = extractTSFile;
8
8
  exports.restoreAllOriginals = restoreAllOriginals;
9
9
  exports.extractVueAndSvelte = extractVueAndSvelte;
10
10
  const core_1 = require("@swc/core");
11
- const fs_1 = __importDefault(require("fs"));
11
+ const promises_1 = require("fs/promises");
12
12
  const path_1 = __importDefault(require("path"));
13
13
  const generatedTsMap = new Map();
14
14
  exports.generatedTsMap = generatedTsMap;
@@ -159,11 +159,11 @@ function expressionToString(expr) {
159
159
  console.warn(`css.props: Argument unsupported ${expr.type}: Use css.create instead.`);
160
160
  return '';
161
161
  }
162
- function extractCssProps(ast) {
162
+ async function extractCssProps(ast) {
163
163
  const propsMatches = [];
164
164
  try {
165
- visit(ast, {
166
- CallExpression: (node) => {
165
+ await visit(ast, {
166
+ CallExpression: async (node) => {
167
167
  if (node.callee.type === 'MemberExpression' &&
168
168
  node.callee.object.type === 'Identifier' &&
169
169
  node.callee.object.value === 'css' &&
@@ -176,7 +176,7 @@ function extractCssProps(ast) {
176
176
  if (arg.expression.type === 'ConditionalExpression' ||
177
177
  (arg.expression.type === 'BinaryExpression' &&
178
178
  arg.expression.operator === '&&')) {
179
- const styles = extractStyleObjectsFromExpression(arg.expression);
179
+ const styles = await extractStyleObjectsFromExpression(arg.expression);
180
180
  conditionalStyleObjects.push(...styles);
181
181
  }
182
182
  else {
@@ -237,23 +237,23 @@ function extractStyleObjectsFromExpression(expression) {
237
237
  }
238
238
  return [];
239
239
  }
240
- function extractStaticStringLiteralVariable(ast) {
240
+ async function extractStaticStringLiteralVariable(ast) {
241
241
  const matches = [];
242
242
  try {
243
- visit(ast, {
244
- VariableDeclaration: (node) => {
243
+ for (const node of ast.body) {
244
+ if (node.type === 'VariableDeclaration') {
245
245
  const allStringLiterals = node.declarations.length > 0 &&
246
246
  node.declarations.every((decl) => decl.init && decl.init.type === 'StringLiteral');
247
247
  if (allStringLiterals) {
248
- const { code: extractedCode } = (0, core_1.printSync)({
248
+ const { code: extractedCode } = await (0, core_1.print)({
249
249
  type: 'Module',
250
250
  body: [node],
251
251
  span: { start: 0, end: 0, ctxt: 0 },
252
252
  });
253
253
  matches.push(extractedCode.trim());
254
254
  }
255
- },
256
- });
255
+ }
256
+ }
257
257
  }
258
258
  catch (e) {
259
259
  console.error(`Failed to parse code to extract static string literal variables: ${e}`);
@@ -286,22 +286,22 @@ function extractCssPropsFromTemplate(code) {
286
286
  }
287
287
  return matches;
288
288
  }
289
- function visit(node, visitor) {
289
+ async function visit(node, visitor) {
290
290
  if (!node)
291
291
  return;
292
292
  const visitorFunc = visitor[node.type];
293
293
  if (visitorFunc) {
294
- visitorFunc(node);
294
+ await visitorFunc(node);
295
295
  }
296
296
  for (const key in node) {
297
297
  if (typeof node[key] === 'object' && node[key] !== null) {
298
298
  if (Array.isArray(node[key])) {
299
299
  for (const child of node[key]) {
300
- visit(child, visitor);
300
+ await visit(child, visitor);
301
301
  }
302
302
  }
303
303
  else {
304
- visit(node[key], visitor);
304
+ await visit(node[key], visitor);
305
305
  }
306
306
  }
307
307
  }
@@ -336,10 +336,10 @@ function importDeclarationToString(node) {
336
336
  }
337
337
  return `import '${source}';`;
338
338
  }
339
- function extractImportDeclarations(ast) {
339
+ async function extractImportDeclarations(ast) {
340
340
  const importDeclarations = [];
341
341
  try {
342
- visit(ast, {
342
+ await visit(ast, {
343
343
  ImportDeclaration: (node) => {
344
344
  importDeclarations.push(importDeclarationToString(node));
345
345
  },
@@ -350,11 +350,11 @@ function extractImportDeclarations(ast) {
350
350
  }
351
351
  return importDeclarations.join('\n');
352
352
  }
353
- function extractCssMethod(ast, methodName) {
353
+ async function extractCssMethod(ast, methodName) {
354
354
  const matches = [];
355
355
  try {
356
- visit(ast, {
357
- VariableDeclaration: (node) => {
356
+ for (const node of ast.body) {
357
+ if (node.type === 'VariableDeclaration') {
358
358
  const containsCssMethod = node.declarations.some((decl) => decl.init &&
359
359
  decl.init.type === 'CallExpression' &&
360
360
  decl.init.callee.type === 'MemberExpression' &&
@@ -363,15 +363,15 @@ function extractCssMethod(ast, methodName) {
363
363
  decl.init.callee.property.type === 'Identifier' &&
364
364
  decl.init.callee.property.value === methodName);
365
365
  if (containsCssMethod && node.span) {
366
- const { code: extractedCode } = (0, core_1.printSync)({
366
+ const { code: extractedCode } = await (0, core_1.print)({
367
367
  type: 'Module',
368
368
  body: [node],
369
369
  span: { start: 0, end: 0, ctxt: 0 },
370
370
  });
371
371
  matches.push(extractedCode.trim());
372
372
  }
373
- },
374
- });
373
+ }
374
+ }
375
375
  }
376
376
  catch (e) {
377
377
  console.error(`Failed to parse code to extract css.${methodName}: ${e}`);
@@ -382,7 +382,7 @@ async function extractVueAndSvelte(filePath) {
382
382
  const ext = path_1.default.extname(filePath);
383
383
  if (!(ext === '.svelte' || ext === '.vue'))
384
384
  return filePath;
385
- const code = fs_1.default.readFileSync(filePath, 'utf8');
385
+ const code = await (0, promises_1.readFile)(filePath, 'utf8');
386
386
  const lines = code.split(/\r?\n/);
387
387
  let inScript = false;
388
388
  const contentLines = [];
@@ -401,30 +401,29 @@ async function extractVueAndSvelte(filePath) {
401
401
  }
402
402
  }
403
403
  const tsCode = contentLines.join('\n');
404
+ const tsPath = filePath.replace(ext, '.ts');
404
405
  if (!tsCode.trim()) {
405
- const tsPath = filePath.replace(ext, '.ts');
406
- fs_1.default.writeFileSync(tsPath, '', 'utf8');
407
- generatedTsMap.set(filePath, tsPath);
406
+ generatedTsMap.set(filePath, '');
408
407
  return tsPath;
409
408
  }
410
- const ast = (0, core_1.parseSync)(tsCode, {
409
+ const ast = await (0, core_1.parse)(tsCode, {
411
410
  syntax: 'typescript',
412
411
  tsx: true,
413
412
  });
414
- const propsFromScript = extractCssProps(ast);
413
+ const propsFromScript = await extractCssProps(ast);
415
414
  const propsFromTemplate = extractCssPropsFromTemplate(code);
416
415
  const propsMatches = [...new Set([...propsFromScript, ...propsFromTemplate])];
417
416
  const calls = propsMatches
418
417
  .filter(Boolean)
419
418
  .map((call) => `${call};`)
420
419
  .join('\n');
421
- const importSection = extractImportDeclarations(ast);
422
- const staticVariableSection = extractStaticStringLiteralVariable(ast);
423
- const cssCreateSection = extractCssMethod(ast, 'create');
424
- const cssKeyframesSection = extractCssMethod(ast, 'keyframes');
425
- const cssViewTransitionSection = extractCssMethod(ast, 'viewTransition');
426
- const cssDefineConstsSection = extractCssMethod(ast, 'defineConsts');
427
- const cssDefineTokensSection = extractCssMethod(ast, 'defineTokens');
420
+ const importSection = await extractImportDeclarations(ast);
421
+ 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');
428
427
  let finalCode = '';
429
428
  if (importSection)
430
429
  finalCode += importSection + '\n';
@@ -442,25 +441,23 @@ async function extractVueAndSvelte(filePath) {
442
441
  finalCode += cssCreateSection + '\n';
443
442
  if (calls)
444
443
  finalCode += calls + '\n';
445
- const tsPath = filePath.replace(ext, '.ts');
446
- fs_1.default.writeFileSync(tsPath, finalCode, 'utf8');
447
- generatedTsMap.set(filePath, tsPath);
444
+ generatedTsMap.set(filePath, finalCode);
448
445
  return tsPath;
449
446
  }
450
447
  async function extractTSFile(filePath) {
451
- const code = fs_1.default.readFileSync(filePath, 'utf8');
452
- const ast = (0, core_1.parseSync)(code, {
448
+ const code = await (0, promises_1.readFile)(filePath, 'utf8');
449
+ const ast = await (0, core_1.parse)(code, {
453
450
  syntax: 'typescript',
454
451
  tsx: true,
455
452
  });
456
- const importSection = extractImportDeclarations(ast);
457
- const staticVariableSection = extractStaticStringLiteralVariable(ast);
458
- const cssCreateSection = extractCssMethod(ast, 'create');
459
- const cssKeyframesSection = extractCssMethod(ast, 'keyframes');
460
- const cssViewTransitionSection = extractCssMethod(ast, 'viewTransition');
461
- const cssDefineConstsSection = extractCssMethod(ast, 'defineConsts');
462
- const cssDefineTokensSection = extractCssMethod(ast, 'defineTokens');
463
- const propsMatches = extractCssProps(ast);
453
+ const importSection = await extractImportDeclarations(ast);
454
+ 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);
464
461
  const calls = propsMatches
465
462
  .filter(Boolean)
466
463
  .map((call) => `${call};`)
@@ -481,18 +478,11 @@ async function extractTSFile(filePath) {
481
478
  if (cssCreateSection)
482
479
  finalCode += cssCreateSection + '\n';
483
480
  finalCode += calls;
484
- const ext = path_1.default.extname(filePath);
485
- const tempFilePath = filePath.replace(ext, '-temp.ts');
486
- fs_1.default.writeFileSync(tempFilePath, finalCode, 'utf8');
487
- generatedTsMap.set(filePath, tempFilePath);
481
+ const tempFilePath = filePath.replace(path_1.default.extname(filePath), '-temp.ts');
482
+ generatedTsMap.set(filePath, finalCode);
488
483
  return tempFilePath;
489
484
  }
490
485
  async function restoreAllOriginals() {
491
- for (const [originalPath, genPath] of generatedTsMap.entries()) {
492
- if (genPath !== originalPath && fs_1.default.existsSync(genPath)) {
493
- fs_1.default.unlinkSync(genPath);
494
- }
495
- }
496
486
  generatedTsMap.clear();
497
487
  }
498
488
  process.on('uncaughtException', async (error) => {
package/dist/index.js CHANGED
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
- const fs_1 = require("fs");
8
7
  const promises_1 = require("fs/promises");
9
8
  const postcss_1 = __importDefault(require("postcss"));
10
9
  const postcss_combine_media_query_1 = __importDefault(require("postcss-combine-media-query"));
@@ -14,7 +13,7 @@ const core_1 = require("@swc/core");
14
13
  const find_up_1 = require("find-up");
15
14
  const processors_1 = require("@plumeria/core/processors");
16
15
  const extract_1 = require("./extract");
17
- async function generateStats(buildTime) {
16
+ async function generateStats(buildTime, coreFilePath) {
18
17
  const cssCode = await (0, promises_1.readFile)(coreFilePath, 'utf8');
19
18
  const cssSize = Buffer.byteLength(cssCode, 'utf8');
20
19
  let rules = 0;
@@ -48,177 +47,199 @@ async function generateStats(buildTime) {
48
47
  console.log(`Build time: ${buildTime.toFixed(2)}s`);
49
48
  console.log('────────────────────────────\n');
50
49
  }
51
- let projectRoot;
52
- const workspaceRootFile = (0, find_up_1.findUpSync)((directory) => {
53
- const pnpmWsPath = path_1.default.join(directory, 'pnpm-workspace.yaml');
54
- if ((0, fs_1.existsSync)(pnpmWsPath)) {
55
- return pnpmWsPath;
56
- }
57
- const pkgJsonPath = path_1.default.join(directory, 'package.json');
58
- if ((0, fs_1.existsSync)(pkgJsonPath)) {
50
+ async function main() {
51
+ let projectRoot;
52
+ const workspaceRootFile = await (0, find_up_1.findUp)(async (directory) => {
53
+ const pnpmWsPath = path_1.default.join(directory, 'pnpm-workspace.yaml');
54
+ try {
55
+ await (0, promises_1.access)(pnpmWsPath);
56
+ return pnpmWsPath;
57
+ }
58
+ catch {
59
+ }
60
+ const pkgJsonPath = path_1.default.join(directory, 'package.json');
59
61
  try {
60
- const pkgJson = JSON.parse((0, fs_1.readFileSync)(pkgJsonPath, 'utf-8'));
62
+ await (0, promises_1.access)(pkgJsonPath);
63
+ const pkgJson = JSON.parse(await (0, promises_1.readFile)(pkgJsonPath, 'utf-8'));
61
64
  if (pkgJson.workspaces) {
62
65
  return pkgJsonPath;
63
66
  }
64
67
  }
65
- catch (err) {
66
- console.error(err);
68
+ catch {
67
69
  }
68
- }
69
- return undefined;
70
- });
71
- if (workspaceRootFile) {
72
- projectRoot = path_1.default.dirname(workspaceRootFile);
73
- }
74
- else {
75
- const singleProjectRootFile = (0, find_up_1.findUpSync)('package.json');
76
- if (singleProjectRootFile) {
77
- projectRoot = path_1.default.dirname(singleProjectRootFile);
70
+ return undefined;
71
+ });
72
+ if (workspaceRootFile) {
73
+ projectRoot = path_1.default.dirname(workspaceRootFile);
78
74
  }
79
75
  else {
80
- projectRoot = process.cwd();
76
+ const singleProjectRootFile = await (0, find_up_1.findUp)('package.json');
77
+ if (singleProjectRootFile) {
78
+ projectRoot = path_1.default.dirname(singleProjectRootFile);
79
+ }
80
+ else {
81
+ projectRoot = process.cwd();
82
+ }
81
83
  }
82
- }
83
- let coreFilePath;
84
- const coreSourcePackageJsonPath = path_1.default.join(process.cwd(), 'package.json');
85
- const coreSourcePackageJson = JSON.parse((0, fs_1.readFileSync)(coreSourcePackageJsonPath, 'utf-8'));
86
- const dependencies = {
87
- ...coreSourcePackageJson.dependencies,
88
- ...coreSourcePackageJson.devDependencies,
89
- };
90
- const coreVersion = dependencies['@plumeria/core'];
91
- const resolvedCorePackageJsonPath = require.resolve('@plumeria/core/package.json', {
92
- paths: [projectRoot, process.cwd()],
93
- });
94
- if (workspaceRootFile) {
95
- if (coreVersion.includes('workspace')) {
96
- coreFilePath = path_1.default.join(path_1.default.dirname(resolvedCorePackageJsonPath), 'stylesheet.css');
84
+ let coreFilePath;
85
+ const coreSourcePackageJsonPath = path_1.default.join(process.cwd(), 'package.json');
86
+ const coreSourcePackageJson = JSON.parse(await (0, promises_1.readFile)(coreSourcePackageJsonPath, 'utf-8'));
87
+ const dependencies = {
88
+ ...coreSourcePackageJson.dependencies,
89
+ ...coreSourcePackageJson.devDependencies,
90
+ };
91
+ const coreVersion = dependencies['@plumeria/core'];
92
+ const resolvedCorePackageJsonPath = require.resolve('@plumeria/core/package.json', {
93
+ paths: [projectRoot, process.cwd()],
94
+ });
95
+ if (workspaceRootFile) {
96
+ if (coreVersion.includes('workspace')) {
97
+ coreFilePath = path_1.default.join(path_1.default.dirname(resolvedCorePackageJsonPath), 'stylesheet.css');
98
+ }
99
+ else {
100
+ const corePackageJson = JSON.parse(await (0, promises_1.readFile)(resolvedCorePackageJsonPath, 'utf-8'));
101
+ const exactCoreVersion = corePackageJson.version;
102
+ coreFilePath = path_1.default.join(projectRoot, 'node_modules', '.pnpm', `@plumeria+core@${exactCoreVersion}`, 'node_modules', '@plumeria', 'core', 'stylesheet.css');
103
+ }
97
104
  }
98
105
  else {
99
- const corePackageJson = JSON.parse((0, fs_1.readFileSync)(resolvedCorePackageJsonPath, 'utf-8'));
100
- const exactCoreVersion = corePackageJson.version;
101
- coreFilePath = path_1.default.join(projectRoot, 'node_modules', '.pnpm', `@plumeria+core@${exactCoreVersion}`, 'node_modules', '@plumeria', 'core', 'stylesheet.css');
102
- }
103
- }
104
- else {
105
- coreFilePath = path_1.default.join(path_1.default.dirname(resolvedCorePackageJsonPath), 'stylesheet.css');
106
- }
107
- const cleanUp = async () => {
108
- if (process.env.CI && (0, fs_1.existsSync)(coreFilePath)) {
109
- (0, fs_1.unlinkSync)(coreFilePath);
110
- console.log('File deleted successfully');
111
- }
112
- try {
113
- await (0, promises_1.writeFile)(coreFilePath, '', 'utf-8');
114
- }
115
- catch (err) {
116
- console.error('An error occurred:', err);
117
- }
118
- };
119
- function isCSS(filePath) {
120
- if ((0, fs_1.statSync)(filePath).isDirectory()) {
121
- return false;
106
+ coreFilePath = path_1.default.join(path_1.default.dirname(resolvedCorePackageJsonPath), 'stylesheet.css');
122
107
  }
123
- const code = (0, fs_1.readFileSync)(filePath, 'utf8');
124
- const ast = (0, core_1.parseSync)(code, {
125
- syntax: 'typescript',
126
- tsx: filePath.endsWith('.tsx'),
127
- decorators: false,
128
- dynamicImport: true,
129
- });
130
- let found = false;
131
- function visit(node) {
132
- if (node.type === 'MemberExpression' && node.property?.value) {
133
- if (node.object?.type === 'Identifier' && node.object.value === 'css') {
134
- if (node.property.value === 'props') {
135
- found = true;
108
+ const cleanUp = async () => {
109
+ if (process.env.CI) {
110
+ try {
111
+ await (0, promises_1.access)(coreFilePath);
112
+ await (0, promises_1.unlink)(coreFilePath);
113
+ console.log('File deleted successfully');
114
+ }
115
+ catch (error) {
116
+ if (error.code !== 'ENOENT') {
117
+ console.error(`Error deleting ${coreFilePath}:`, error);
136
118
  }
137
119
  }
138
120
  }
139
- for (const key in node) {
140
- const value = node[key];
141
- if (value && typeof value === 'object') {
142
- if (Array.isArray(value)) {
143
- for (const item of value) {
144
- visit(item);
121
+ try {
122
+ await (0, promises_1.writeFile)(coreFilePath, '', 'utf-8');
123
+ }
124
+ catch (err) {
125
+ console.error('An error occurred:', err);
126
+ }
127
+ };
128
+ async function isCSS(code, filePath) {
129
+ if (!code.includes('css.props')) {
130
+ return false;
131
+ }
132
+ const ast = await (0, core_1.parse)(code, {
133
+ syntax: 'typescript',
134
+ tsx: filePath.endsWith('.tsx'),
135
+ decorators: false,
136
+ dynamicImport: true,
137
+ });
138
+ let found = false;
139
+ function visit(node) {
140
+ if (node.type === 'MemberExpression' && node.property?.value) {
141
+ if (node.object?.type === 'Identifier' && node.object.value === 'css') {
142
+ if (node.property.value === 'props') {
143
+ found = true;
145
144
  }
146
145
  }
147
- else {
148
- visit(value);
146
+ }
147
+ for (const key in node) {
148
+ const value = node[key];
149
+ if (value && typeof value === 'object') {
150
+ if (Array.isArray(value)) {
151
+ for (const item of value) {
152
+ visit(item);
153
+ }
154
+ }
155
+ else {
156
+ visit(value);
157
+ }
149
158
  }
150
159
  }
151
160
  }
152
- }
153
- visit(ast);
154
- return found;
155
- }
156
- async function optimizeCSS() {
157
- const cssCode = await (0, promises_1.readFile)(coreFilePath, 'utf8');
158
- const merged = (0, postcss_1.default)([(0, postcss_combine_media_query_1.default)()]).process(cssCode, {
159
- from: coreFilePath,
160
- to: coreFilePath,
161
- });
162
- const light = (0, lightningcss_1.transform)({
163
- filename: coreFilePath,
164
- code: Buffer.from(merged.css),
165
- minify: process.env.NODE_ENV === 'production',
166
- targets: {
167
- safari: 16,
168
- edge: 110,
169
- firefox: 110,
170
- chrome: 110,
171
- },
172
- });
173
- const optimizedCss = Buffer.from(light.code).toString('utf-8');
174
- await (0, promises_1.writeFile)(coreFilePath, optimizedCss, 'utf-8');
175
- }
176
- (async () => {
177
- const startTime = performance.now();
178
- await cleanUp();
179
- const scanRoot = process.cwd();
180
- const files = (0, fs_1.globSync)('**/*.{js,jsx,ts,tsx,vue,svelte}', {
181
- cwd: scanRoot,
182
- exclude: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/.next/**'],
183
- });
184
- const projectName = path_1.default.basename(projectRoot);
185
- const filesSupportExtensions = [];
186
- for (const file of files) {
187
- const ext = path_1.default.extname(file);
188
- if (ext === '.vue' || ext === '.svelte') {
189
- const tsFile = await (0, extract_1.extractVueAndSvelte)(file);
190
- filesSupportExtensions.push(tsFile);
191
- }
192
- else {
193
- const tempFile = await (0, extract_1.extractTSFile)(file);
194
- filesSupportExtensions.push(tempFile);
161
+ visit(ast);
162
+ return found;
163
+ }
164
+ async function optimizeCSS() {
165
+ const cssCode = await (0, promises_1.readFile)(coreFilePath, 'utf8');
166
+ const merged = (0, postcss_1.default)([(0, postcss_combine_media_query_1.default)()]).process(cssCode, {
167
+ from: coreFilePath,
168
+ to: coreFilePath,
169
+ });
170
+ const light = (0, lightningcss_1.transform)({
171
+ filename: coreFilePath,
172
+ code: Buffer.from(merged.css),
173
+ minify: process.env.NODE_ENV === 'production',
174
+ targets: {
175
+ safari: 16,
176
+ edge: 110,
177
+ firefox: 110,
178
+ chrome: 110,
179
+ },
180
+ });
181
+ const optimizedCss = Buffer.from(light.code).toString('utf-8');
182
+ await (0, promises_1.writeFile)(coreFilePath, optimizedCss, 'utf-8');
183
+ }
184
+ (async () => {
185
+ const startTime = performance.now();
186
+ await cleanUp();
187
+ const scanRoot = process.cwd();
188
+ const files = [];
189
+ for await (const entry of (0, promises_1.glob)('**/*.{js,jsx,ts,tsx,vue,svelte}', {
190
+ cwd: scanRoot,
191
+ exclude: [
192
+ '**/node_modules/**',
193
+ '**/dist/**',
194
+ '**/build/**',
195
+ '**/.next/**',
196
+ ],
197
+ })) {
198
+ files.push(entry);
195
199
  }
196
- }
197
- const styleFiles = filesSupportExtensions
198
- .filter((file) => isCSS(file))
199
- .sort();
200
- const tempToOriginalMap = new Map();
201
- for (const [original, temp] of extract_1.generatedTsMap.entries()) {
202
- tempToOriginalMap.set(temp, original);
203
- }
204
- for (let i = 0; i < styleFiles.length; i++) {
205
- await (0, execute_1.execute)(path_1.default.resolve(styleFiles[i]));
206
- if (process.argv.includes('--paths')) {
207
- const originalFile = tempToOriginalMap.get(styleFiles[i]);
208
- console.log(`✅: ${projectName}/${path_1.default.relative(projectRoot, originalFile)}`);
200
+ const projectName = path_1.default.basename(projectRoot);
201
+ const tempToOriginalMap = new Map();
202
+ const filesSupportExtensions = await Promise.all(files.map(async (file) => {
203
+ const ext = path_1.default.extname(file);
204
+ let tempFile;
205
+ if (ext === '.vue' || ext === '.svelte') {
206
+ tempFile = await (0, extract_1.extractVueAndSvelte)(file);
207
+ }
208
+ else {
209
+ tempFile = await (0, extract_1.extractTSFile)(file);
210
+ }
211
+ tempToOriginalMap.set(tempFile, file);
212
+ return tempFile;
213
+ }));
214
+ const styleFiles = await Promise.all(filesSupportExtensions.map(async (file) => {
215
+ const originalFile = tempToOriginalMap.get(file);
216
+ const code = extract_1.generatedTsMap.get(originalFile);
217
+ const isCssFile = code ? await isCSS(code, file) : false;
218
+ return isCssFile ? file : null;
219
+ }))
220
+ .then((results) => results.filter(Boolean))
221
+ .then((results) => results.sort());
222
+ for (const file of styleFiles) {
223
+ const originalFile = tempToOriginalMap.get(file);
224
+ const code = extract_1.generatedTsMap.get(originalFile);
225
+ if (code) {
226
+ await (0, promises_1.writeFile)(file, code, 'utf8');
227
+ await (0, execute_1.execute)(path_1.default.resolve(file));
228
+ if (process.argv.includes('--paths')) {
229
+ console.log(`✅: ${projectName}/${path_1.default.relative(projectRoot, originalFile)}`);
230
+ }
231
+ await (0, promises_1.unlink)(file);
232
+ }
209
233
  }
210
- }
211
- for (let i = 0; i < styleFiles.length; i++) {
212
234
  await (0, processors_1.buildGlobal)(coreFilePath);
213
- }
214
- for (let i = 0; i < styleFiles.length; i++) {
215
235
  await (0, processors_1.buildProps)(coreFilePath);
216
- }
217
- await optimizeCSS();
218
- await (0, extract_1.restoreAllOriginals)();
219
- if (process.argv.includes('--stats')) {
220
- const endTime = performance.now();
221
- const buildTime = (endTime - startTime) / 1000;
222
- await generateStats(buildTime);
223
- }
224
- })();
236
+ await optimizeCSS();
237
+ await (0, extract_1.restoreAllOriginals)();
238
+ if (process.argv.includes('--stats')) {
239
+ const endTime = performance.now();
240
+ const buildTime = (endTime - startTime) / 1000;
241
+ await generateStats(buildTime, coreFilePath);
242
+ }
243
+ })();
244
+ }
245
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "0.25.1",
3
+ "version": "0.25.2",
4
4
  "description": "Plumeria Rust-based compiler",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,7 @@
21
21
  "lightningcss": "^1.30.2",
22
22
  "postcss": "^8.5.6",
23
23
  "postcss-combine-media-query": "^2.1.0",
24
- "rscute": "^1.0.0"
24
+ "rscute": "^1.0.2"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"