@plumeria/compiler 0.16.2 → 0.17.1

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/bin/css.js CHANGED
@@ -1,32 +1,28 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const fs = require('fs');
4
3
  const path = require('path');
5
4
  const { execSync } = require('child_process');
6
5
  const { styleText } = require('util');
7
6
 
8
7
  try {
9
8
  const checkMark = styleText('greenBright', '✓');
10
- const isPnpm = fs.existsSync(path.join(process.cwd(), 'node_modules/.pnpm'));
11
9
  const typecheck = process.argv.includes('--type-check');
12
10
 
13
- if (typecheck)
11
+ if (typecheck) {
14
12
  execSync('tsc --noEmit --incremental false', {
15
13
  stdio: 'inherit',
16
14
  cwd: process.cwd(),
17
15
  });
18
-
19
- const plumeriaPath = isPnpm
20
- ? findPnpmPath('@plumeria+compiler@', 'node_modules/@plumeria')
21
- : path.join(process.cwd(), 'node_modules/@plumeria');
16
+ }
22
17
 
23
18
  const a1 = process.argv.includes('--view') ? '--view' : '';
24
19
  const a2 = process.argv.includes('--paths') ? '--paths' : '';
25
20
  const argv = [a1, a2].join(' ');
26
21
 
27
- execSync(`node -r rscute compiler/dist/index.js ` + argv, {
22
+ const indexPath = path.resolve(__dirname, '../dist/index.js');
23
+
24
+ execSync(`node -r rscute ${indexPath} ` + argv, {
28
25
  stdio: 'inherit',
29
- cwd: plumeriaPath,
30
26
  });
31
27
 
32
28
  const compilation = typecheck ? 'Type-check completed' : '';
@@ -35,14 +31,3 @@ try {
35
31
  console.error('Compilation failed:', error.message);
36
32
  process.exit(1);
37
33
  }
38
-
39
- function findPnpmPath(arg1, arg2) {
40
- const pnpmPath = path.join(process.cwd(), 'node_modules/.pnpm');
41
- const pnpmDir = fs.readdirSync(pnpmPath).find((dir) => dir.startsWith(arg1));
42
-
43
- if (!pnpmDir) {
44
- throw new Error(`Could not find ${arg1} package in pnpm directory`);
45
- }
46
-
47
- return path.join(pnpmPath, pnpmDir, arg2);
48
- }
package/dist/extract.js CHANGED
@@ -210,51 +210,29 @@ function parseCssPropsArguments(args) {
210
210
  }
211
211
  return results;
212
212
  }
213
- async function extractVueAndSvelteAndAstro(filePath) {
213
+ async function extractVueAndSvelte(filePath) {
214
214
  const ext = path.extname(filePath);
215
- if (!(ext === '.svelte' || ext === '.vue' || ext === '.astro'))
215
+ if (!(ext === '.svelte' || ext === '.vue'))
216
216
  return filePath;
217
217
  const code = fs.readFileSync(filePath, 'utf8');
218
- let tsCode = '';
219
218
  const lines = code.split(/\r?\n/);
220
- if (ext === '.astro') {
221
- let inFrontmatter = false;
222
- const contentLines = [];
223
- for (const line of lines) {
224
- const trimmed = line.trim();
225
- if (!inFrontmatter && trimmed === '---') {
226
- inFrontmatter = true;
227
- continue;
228
- }
229
- if (inFrontmatter && trimmed === '---') {
230
- inFrontmatter = false;
231
- continue;
232
- }
233
- if (inFrontmatter) {
234
- contentLines.push(line);
235
- }
219
+ let inScript = false;
220
+ const contentLines = [];
221
+ for (const line of lines) {
222
+ const trimmed = line.trim();
223
+ if (!inScript && /^<script\b/.test(trimmed)) {
224
+ inScript = true;
225
+ continue;
236
226
  }
237
- tsCode = contentLines.join('\n');
238
- }
239
- else {
240
- let inScript = false;
241
- const contentLines = [];
242
- for (const line of lines) {
243
- const trimmed = line.trim();
244
- if (!inScript && /^<script\b/.test(trimmed)) {
245
- inScript = true;
246
- continue;
247
- }
248
- if (inScript && /^<\/script>/.test(trimmed)) {
249
- inScript = false;
250
- continue;
251
- }
252
- if (inScript) {
253
- contentLines.push(line);
254
- }
227
+ if (inScript && /^<\/script>/.test(trimmed)) {
228
+ inScript = false;
229
+ continue;
230
+ }
231
+ if (inScript) {
232
+ contentLines.push(line);
255
233
  }
256
- tsCode = contentLines.join('\n');
257
234
  }
235
+ const tsCode = contentLines.join('\n');
258
236
  const propsMatches = [...extractCssProps(tsCode), ...extractCssProps(code)];
259
237
  const calls = propsMatches
260
238
  .filter(Boolean)
@@ -337,5 +315,5 @@ process.on('unhandledRejection', async (reason, promise) => {
337
315
  module.exports = {
338
316
  extractTSFile,
339
317
  restoreAllOriginals,
340
- extractVueAndSvelteAndAstro,
318
+ extractVueAndSvelte,
341
319
  };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path = require('path');
4
+ const fs = require('fs');
4
5
  const { unlinkSync, existsSync, readFileSync, statSync } = require('fs');
5
6
  const { readFile, writeFile } = require('fs/promises');
6
7
  const { glob } = require('@rust-gear/glob');
@@ -8,13 +9,54 @@ const postcss = require('postcss');
8
9
  const combineSelectors = require('postcss-combine-duplicated-selectors');
9
10
  const combineMediaQuery = require('postcss-combine-media-query');
10
11
  const { execute } = require('rscute/execute');
11
- const { transform } = require('lightningcss');
12
+ const { transform: lightningCSSTransform } = require('lightningcss');
12
13
  const { parseSync } = require('@swc/core');
14
+ const { findUpSync } = require('find-up');
13
15
  const { buildGlobal, buildProps } = require('@plumeria/core/processors');
14
- const { extractTSFile, restoreAllOriginals, extractVueAndSvelteAndAstro, } = require('./extract');
15
- const projectRoot = process.cwd().split('node_modules')[0];
16
- const directPath = path.join(projectRoot, 'node_modules/@plumeria/core');
17
- const coreFilePath = path.join(directPath, 'stylesheet.css');
16
+ const { extractTSFile, restoreAllOriginals, extractVueAndSvelte, } = require('./extract');
17
+ let projectRoot;
18
+ const workspaceRootFile = findUpSync((directory) => {
19
+ const pnpmWsPath = path.join(directory, 'pnpm-workspace.yaml');
20
+ if (fs.existsSync(pnpmWsPath)) {
21
+ return pnpmWsPath;
22
+ }
23
+ const pkgJsonPath = path.join(directory, 'package.json');
24
+ if (fs.existsSync(pkgJsonPath)) {
25
+ try {
26
+ const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
27
+ if (pkgJson.workspaces) {
28
+ return pkgJsonPath;
29
+ }
30
+ }
31
+ catch (err) {
32
+ console.error(err);
33
+ }
34
+ }
35
+ return undefined;
36
+ });
37
+ if (workspaceRootFile) {
38
+ projectRoot = path.dirname(workspaceRootFile);
39
+ }
40
+ else {
41
+ const singleProjectRootFile = findUpSync('package.json');
42
+ if (singleProjectRootFile) {
43
+ projectRoot = path.dirname(singleProjectRootFile);
44
+ }
45
+ else {
46
+ projectRoot = process.cwd();
47
+ }
48
+ }
49
+ let coreFilePath;
50
+ if (workspaceRootFile) {
51
+ const coreSourcePackageJsonPath = path.join(projectRoot, 'packages', 'core', 'package.json');
52
+ const coreSourcePackageJson = JSON.parse(fs.readFileSync(coreSourcePackageJsonPath, 'utf-8'));
53
+ const coreVersion = coreSourcePackageJson.version;
54
+ coreFilePath = path.join(projectRoot, 'node_modules', '.pnpm', `@plumeria+core@${coreVersion}`, 'node_modules', '@plumeria', 'core', 'stylesheet.css');
55
+ }
56
+ else {
57
+ const coreInstalledPath = path.dirname(require.resolve('@plumeria/core/package.json'));
58
+ coreFilePath = path.join(coreInstalledPath, 'stylesheet.css');
59
+ }
18
60
  const cleanUp = async () => {
19
61
  if (process.env.CI && existsSync(coreFilePath)) {
20
62
  unlinkSync(coreFilePath);
@@ -79,7 +121,7 @@ async function optimizeCSS() {
79
121
  from: coreFilePath,
80
122
  to: coreFilePath,
81
123
  });
82
- const light = transform({
124
+ const light = lightningCSSTransform({
83
125
  filename: coreFilePath,
84
126
  code: Buffer.from(merged.css),
85
127
  minify: process.env.NODE_ENV === 'production',
@@ -95,21 +137,18 @@ async function optimizeCSS() {
95
137
  }
96
138
  (async () => {
97
139
  await cleanUp();
98
- const files = await glob(path.join(projectRoot, '**/*.{js,jsx,ts,tsx,vue,svelte,astro}'), {
99
- exclude: [
100
- '**/node_modules/**',
101
- '**/dist/**',
102
- '**/build/**',
103
- '**/.next/**',
104
- ],
105
- cwd: projectRoot,
140
+ const scanRoot = process.cwd();
141
+ const files = await glob('**/*.{js,jsx,ts,tsx,vue,svelte}', {
142
+ cwd: scanRoot,
143
+ absolute: true,
144
+ exclude: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/.next/**'],
106
145
  });
107
146
  const projectName = path.basename(projectRoot);
108
147
  const filesSupportExtensions = [];
109
148
  for (const file of files) {
110
149
  const ext = path.extname(file);
111
150
  if (ext === '.vue' || ext === '.svelte') {
112
- const tsFile = await extractVueAndSvelteAndAstro(file);
151
+ const tsFile = await extractVueAndSvelte(file);
113
152
  filesSupportExtensions.push(tsFile);
114
153
  }
115
154
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "0.16.2",
3
+ "version": "0.17.1",
4
4
  "description": "Plumeria Rust-based compiler",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,13 +16,14 @@
16
16
  "css": "./bin/css.js"
17
17
  },
18
18
  "dependencies": {
19
- "@swc/core": "^1.11.24",
20
19
  "@rust-gear/glob": "^0.2.2",
21
- "rscute": "^0.2.7",
20
+ "@swc/core": "^1.11.24",
22
21
  "lightningcss": "^1.29.3",
23
22
  "postcss": "^8.5.3",
24
23
  "postcss-combine-duplicated-selectors": "^10.0.3",
25
- "postcss-combine-media-query": "^2.0.0"
24
+ "postcss-combine-media-query": "^2.0.0",
25
+ "rscute": "^0.2.7",
26
+ "find-up": "^7.0.0"
26
27
  },
27
28
  "publishConfig": {
28
29
  "access": "public"