@plumeria/compiler 0.20.4 → 0.21.0
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 +16 -15
- package/dist/index.js +83 -49
- package/package.json +1 -1
package/dist/extract.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
exports.extractTSFile = extractTSFile;
|
|
7
|
+
exports.restoreAllOriginals = restoreAllOriginals;
|
|
8
|
+
exports.extractVueAndSvelte = extractVueAndSvelte;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
5
11
|
const generatedTsMap = new Map();
|
|
6
12
|
function isInComment(code, position) {
|
|
7
13
|
const beforePosition = code.substring(0, position);
|
|
@@ -274,10 +280,10 @@ function parseCssPropsArguments(args) {
|
|
|
274
280
|
return results;
|
|
275
281
|
}
|
|
276
282
|
async function extractVueAndSvelte(filePath) {
|
|
277
|
-
const ext =
|
|
283
|
+
const ext = path_1.default.extname(filePath);
|
|
278
284
|
if (!(ext === '.svelte' || ext === '.vue'))
|
|
279
285
|
return filePath;
|
|
280
|
-
const code =
|
|
286
|
+
const code = fs_1.default.readFileSync(filePath, 'utf8');
|
|
281
287
|
const lines = code.split(/\r?\n/);
|
|
282
288
|
let inScript = false;
|
|
283
289
|
const contentLines = [];
|
|
@@ -336,12 +342,12 @@ async function extractVueAndSvelte(filePath) {
|
|
|
336
342
|
finalCode += calls + '\n';
|
|
337
343
|
}
|
|
338
344
|
const tsPath = filePath.replace(ext, '.ts');
|
|
339
|
-
|
|
345
|
+
fs_1.default.writeFileSync(tsPath, finalCode, 'utf8');
|
|
340
346
|
generatedTsMap.set(filePath, tsPath);
|
|
341
347
|
return tsPath;
|
|
342
348
|
}
|
|
343
349
|
async function extractTSFile(filePath) {
|
|
344
|
-
const code =
|
|
350
|
+
const code = fs_1.default.readFileSync(filePath, 'utf8');
|
|
345
351
|
const importRegex = /^(?:\s*import\s[^;]+;\s*)+/m;
|
|
346
352
|
const importMatch = code.match(importRegex);
|
|
347
353
|
const importSection = importMatch ? importMatch[0] : '';
|
|
@@ -372,16 +378,16 @@ async function extractTSFile(filePath) {
|
|
|
372
378
|
if (cssCreateSection)
|
|
373
379
|
finalCode += cssCreateSection + '\n';
|
|
374
380
|
finalCode += calls;
|
|
375
|
-
const ext =
|
|
381
|
+
const ext = path_1.default.extname(filePath);
|
|
376
382
|
const tempFilePath = filePath.replace(ext, '-temp.ts');
|
|
377
|
-
|
|
383
|
+
fs_1.default.writeFileSync(tempFilePath, finalCode, 'utf8');
|
|
378
384
|
generatedTsMap.set(filePath, tempFilePath);
|
|
379
385
|
return tempFilePath;
|
|
380
386
|
}
|
|
381
387
|
async function restoreAllOriginals() {
|
|
382
388
|
for (const [originalPath, genPath] of generatedTsMap.entries()) {
|
|
383
|
-
if (genPath !== originalPath &&
|
|
384
|
-
|
|
389
|
+
if (genPath !== originalPath && fs_1.default.existsSync(genPath)) {
|
|
390
|
+
fs_1.default.unlinkSync(genPath);
|
|
385
391
|
}
|
|
386
392
|
}
|
|
387
393
|
generatedTsMap.clear();
|
|
@@ -396,8 +402,3 @@ process.on('unhandledRejection', async (reason, promise) => {
|
|
|
396
402
|
await restoreAllOriginals();
|
|
397
403
|
process.exit(1);
|
|
398
404
|
});
|
|
399
|
-
module.exports = {
|
|
400
|
-
extractTSFile,
|
|
401
|
-
restoreAllOriginals,
|
|
402
|
-
extractVueAndSvelte,
|
|
403
|
-
};
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const { extractTSFile, restoreAllOriginals, extractVueAndSvelte, } = require('./extract');
|
|
39
|
+
const path_1 = __importDefault(require("path"));
|
|
40
|
+
const fs_1 = __importStar(require("fs"));
|
|
41
|
+
const promises_1 = require("fs/promises");
|
|
42
|
+
const glob_1 = require("@rust-gear/glob");
|
|
43
|
+
const postcss_1 = __importDefault(require("postcss"));
|
|
44
|
+
const postcss_combine_media_query_1 = __importDefault(require("postcss-combine-media-query"));
|
|
45
|
+
const execute_1 = require("rscute/execute");
|
|
46
|
+
const lightningcss_1 = require("lightningcss");
|
|
47
|
+
const core_1 = require("@swc/core");
|
|
48
|
+
const find_up_1 = require("find-up");
|
|
49
|
+
const processors_1 = require("@plumeria/core/processors");
|
|
50
|
+
const extract_1 = require("./extract");
|
|
16
51
|
let projectRoot;
|
|
17
|
-
const workspaceRootFile = findUpSync((directory) => {
|
|
18
|
-
const pnpmWsPath =
|
|
19
|
-
if (
|
|
52
|
+
const workspaceRootFile = (0, find_up_1.findUpSync)((directory) => {
|
|
53
|
+
const pnpmWsPath = path_1.default.join(directory, 'pnpm-workspace.yaml');
|
|
54
|
+
if (fs_1.default.existsSync(pnpmWsPath)) {
|
|
20
55
|
return pnpmWsPath;
|
|
21
56
|
}
|
|
22
|
-
const pkgJsonPath =
|
|
23
|
-
if (
|
|
57
|
+
const pkgJsonPath = path_1.default.join(directory, 'package.json');
|
|
58
|
+
if (fs_1.default.existsSync(pkgJsonPath)) {
|
|
24
59
|
try {
|
|
25
|
-
const pkgJson = JSON.parse(
|
|
60
|
+
const pkgJson = JSON.parse(fs_1.default.readFileSync(pkgJsonPath, 'utf-8'));
|
|
26
61
|
if (pkgJson.workspaces) {
|
|
27
62
|
return pkgJsonPath;
|
|
28
63
|
}
|
|
@@ -34,20 +69,20 @@ const workspaceRootFile = findUpSync((directory) => {
|
|
|
34
69
|
return undefined;
|
|
35
70
|
});
|
|
36
71
|
if (workspaceRootFile) {
|
|
37
|
-
projectRoot =
|
|
72
|
+
projectRoot = path_1.default.dirname(workspaceRootFile);
|
|
38
73
|
}
|
|
39
74
|
else {
|
|
40
|
-
const singleProjectRootFile = findUpSync('package.json');
|
|
75
|
+
const singleProjectRootFile = (0, find_up_1.findUpSync)('package.json');
|
|
41
76
|
if (singleProjectRootFile) {
|
|
42
|
-
projectRoot =
|
|
77
|
+
projectRoot = path_1.default.dirname(singleProjectRootFile);
|
|
43
78
|
}
|
|
44
79
|
else {
|
|
45
80
|
projectRoot = process.cwd();
|
|
46
81
|
}
|
|
47
82
|
}
|
|
48
83
|
let coreFilePath;
|
|
49
|
-
const coreSourcePackageJsonPath =
|
|
50
|
-
const coreSourcePackageJson = JSON.parse(
|
|
84
|
+
const coreSourcePackageJsonPath = path_1.default.join(process.cwd(), 'package.json');
|
|
85
|
+
const coreSourcePackageJson = JSON.parse(fs_1.default.readFileSync(coreSourcePackageJsonPath, 'utf-8'));
|
|
51
86
|
const dependencies = {
|
|
52
87
|
...coreSourcePackageJson.dependencies,
|
|
53
88
|
...coreSourcePackageJson.devDependencies,
|
|
@@ -58,35 +93,35 @@ const resolvedCorePackageJsonPath = require.resolve('@plumeria/core/package.json
|
|
|
58
93
|
});
|
|
59
94
|
if (workspaceRootFile) {
|
|
60
95
|
if (coreVersion.includes('workspace')) {
|
|
61
|
-
coreFilePath =
|
|
96
|
+
coreFilePath = path_1.default.join(path_1.default.dirname(resolvedCorePackageJsonPath), 'stylesheet.css');
|
|
62
97
|
}
|
|
63
98
|
else {
|
|
64
|
-
const corePackageJson = JSON.parse(
|
|
99
|
+
const corePackageJson = JSON.parse(fs_1.default.readFileSync(resolvedCorePackageJsonPath, 'utf-8'));
|
|
65
100
|
const exactCoreVersion = corePackageJson.version;
|
|
66
|
-
coreFilePath =
|
|
101
|
+
coreFilePath = path_1.default.join(projectRoot, 'node_modules', '.pnpm', `@plumeria+core@${exactCoreVersion}`, 'node_modules', '@plumeria', 'core', 'stylesheet.css');
|
|
67
102
|
}
|
|
68
103
|
}
|
|
69
104
|
else {
|
|
70
|
-
coreFilePath =
|
|
105
|
+
coreFilePath = path_1.default.join(path_1.default.dirname(resolvedCorePackageJsonPath), 'stylesheet.css');
|
|
71
106
|
}
|
|
72
107
|
const cleanUp = async () => {
|
|
73
|
-
if (process.env.CI && existsSync(coreFilePath)) {
|
|
74
|
-
unlinkSync(coreFilePath);
|
|
108
|
+
if (process.env.CI && (0, fs_1.existsSync)(coreFilePath)) {
|
|
109
|
+
(0, fs_1.unlinkSync)(coreFilePath);
|
|
75
110
|
console.log('File deleted successfully');
|
|
76
111
|
}
|
|
77
112
|
try {
|
|
78
|
-
await writeFile(coreFilePath, '', 'utf-8');
|
|
113
|
+
await (0, promises_1.writeFile)(coreFilePath, '', 'utf-8');
|
|
79
114
|
}
|
|
80
115
|
catch (err) {
|
|
81
116
|
console.error('An error occurred:', err);
|
|
82
117
|
}
|
|
83
118
|
};
|
|
84
119
|
function isCSS(filePath) {
|
|
85
|
-
if (statSync(filePath).isDirectory()) {
|
|
120
|
+
if ((0, fs_1.statSync)(filePath).isDirectory()) {
|
|
86
121
|
return false;
|
|
87
122
|
}
|
|
88
|
-
const code = readFileSync(filePath, 'utf8');
|
|
89
|
-
const ast = parseSync(code, {
|
|
123
|
+
const code = (0, fs_1.readFileSync)(filePath, 'utf8');
|
|
124
|
+
const ast = (0, core_1.parseSync)(code, {
|
|
90
125
|
syntax: 'typescript',
|
|
91
126
|
tsx: filePath.endsWith('.tsx'),
|
|
92
127
|
decorators: false,
|
|
@@ -119,12 +154,12 @@ function isCSS(filePath) {
|
|
|
119
154
|
return found;
|
|
120
155
|
}
|
|
121
156
|
async function optimizeCSS() {
|
|
122
|
-
const cssCode = await readFile(coreFilePath, 'utf8');
|
|
123
|
-
const merged =
|
|
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, {
|
|
124
159
|
from: coreFilePath,
|
|
125
160
|
to: coreFilePath,
|
|
126
161
|
});
|
|
127
|
-
const light =
|
|
162
|
+
const light = (0, lightningcss_1.transform)({
|
|
128
163
|
filename: coreFilePath,
|
|
129
164
|
code: Buffer.from(merged.css),
|
|
130
165
|
minify: process.env.NODE_ENV === 'production',
|
|
@@ -136,26 +171,25 @@ async function optimizeCSS() {
|
|
|
136
171
|
},
|
|
137
172
|
});
|
|
138
173
|
const optimizedCss = Buffer.from(light.code).toString('utf-8');
|
|
139
|
-
await writeFile(coreFilePath, optimizedCss, 'utf-8');
|
|
174
|
+
await (0, promises_1.writeFile)(coreFilePath, optimizedCss, 'utf-8');
|
|
140
175
|
}
|
|
141
176
|
(async () => {
|
|
142
177
|
await cleanUp();
|
|
143
178
|
const scanRoot = process.cwd();
|
|
144
|
-
const files = await glob('**/*.{js,jsx,ts,tsx,vue,svelte}', {
|
|
179
|
+
const files = await (0, glob_1.glob)('**/*.{js,jsx,ts,tsx,vue,svelte}', {
|
|
145
180
|
cwd: scanRoot,
|
|
146
|
-
absolute: true,
|
|
147
181
|
exclude: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/.next/**'],
|
|
148
182
|
});
|
|
149
|
-
const projectName =
|
|
183
|
+
const projectName = path_1.default.basename(projectRoot);
|
|
150
184
|
const filesSupportExtensions = [];
|
|
151
185
|
for (const file of files) {
|
|
152
|
-
const ext =
|
|
186
|
+
const ext = path_1.default.extname(file);
|
|
153
187
|
if (ext === '.vue' || ext === '.svelte') {
|
|
154
|
-
const tsFile = await extractVueAndSvelte(file);
|
|
188
|
+
const tsFile = await (0, extract_1.extractVueAndSvelte)(file);
|
|
155
189
|
filesSupportExtensions.push(tsFile);
|
|
156
190
|
}
|
|
157
191
|
else {
|
|
158
|
-
const tempFile = await extractTSFile(file);
|
|
192
|
+
const tempFile = await (0, extract_1.extractTSFile)(file);
|
|
159
193
|
filesSupportExtensions.push(tempFile);
|
|
160
194
|
}
|
|
161
195
|
}
|
|
@@ -163,16 +197,16 @@ async function optimizeCSS() {
|
|
|
163
197
|
.filter((file) => isCSS(file))
|
|
164
198
|
.sort();
|
|
165
199
|
for (let i = 0; i < styleFiles.length; i++) {
|
|
166
|
-
await execute(
|
|
200
|
+
await (0, execute_1.execute)(path_1.default.resolve(styleFiles[i]));
|
|
167
201
|
if (process.argv.includes('--paths'))
|
|
168
|
-
console.log(`✅: ${projectName}/${
|
|
202
|
+
console.log(`✅: ${projectName}/${path_1.default.relative(projectRoot, styleFiles[i])}`);
|
|
169
203
|
}
|
|
170
204
|
for (let i = 0; i < styleFiles.length; i++) {
|
|
171
|
-
await buildGlobal(coreFilePath);
|
|
205
|
+
await (0, processors_1.buildGlobal)(coreFilePath);
|
|
172
206
|
}
|
|
173
207
|
for (let i = 0; i < styleFiles.length; i++) {
|
|
174
|
-
await buildProps(coreFilePath);
|
|
208
|
+
await (0, processors_1.buildProps)(coreFilePath);
|
|
175
209
|
}
|
|
176
210
|
await optimizeCSS();
|
|
177
|
-
await restoreAllOriginals();
|
|
211
|
+
await (0, extract_1.restoreAllOriginals)();
|
|
178
212
|
})();
|