@dimina-kit/compiler 0.0.2-dev.20260718143821 → 0.0.2-dev.20260728065133
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/compile-core.browser.js +5130 -4282
- package/dist/compile-core.node-chunks/chunk-23PCGQQU.js +141 -0
- package/dist/compile-core.node-chunks/{chunk-QVEZ34FP.js → chunk-M62ZDT7T.js} +281 -21
- package/dist/compile-core.node-chunks/{chunk-6734LXNU.js → chunk-QYHGF3MS.js} +75 -4
- package/dist/compile-core.node-chunks/{logic-compiler-VJWEQMXZ.js → logic-compiler-AEZPY2MO.js} +26 -102
- package/dist/compile-core.node-chunks/style-compiler-4PHMBQIC.js +470 -0
- package/dist/compile-core.node-chunks/{view-compiler-3OUFRVZF.js → view-compiler-2SMUHAPD.js} +232 -109
- package/dist/compile-core.node.js +11 -6
- package/dist/pool.node-chunks/{chunk-7F3E2G42.js → chunk-CKQISGZS.js} +281 -21
- package/dist/pool.node-chunks/{chunk-DQNLDQGT.js → chunk-LGB3AH5C.js} +75 -4
- package/dist/pool.node-chunks/chunk-VHWKAXDL.js +141 -0
- package/dist/pool.node-chunks/{chunk-LKL7FBHG.js → chunk-WX4462A5.js} +11 -6
- package/dist/pool.node-chunks/{logic-compiler-HMMTJJWY.js → logic-compiler-P4T4OMTG.js} +26 -102
- package/dist/pool.node-chunks/style-compiler-W7EA2Y7R.js +470 -0
- package/dist/pool.node-chunks/{view-compiler-2VZMJ65O.js → view-compiler-2D7HPYIN.js} +232 -109
- package/dist/pool.node.js +2 -2
- package/dist/stage-worker.browser.js +5337 -4489
- package/dist/stage-worker.node.js +2 -2
- package/package.json +8 -7
- package/scripts/check-wasm-alignment.js +173 -0
- package/dist/compile-core.node-chunks/chunk-2VRS523Z.js +0 -8
- package/dist/compile-core.node-chunks/style-compiler-YWVITCJW.js +0 -288
- package/dist/pool.node-chunks/chunk-KLXXOLDF.js +0 -8
- package/dist/pool.node-chunks/style-compiler-VGVCLQ7X.js +0 -288
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
preloadStage,
|
|
4
4
|
resetCompilerState,
|
|
5
5
|
runStage
|
|
6
|
-
} from "./pool.node-chunks/chunk-
|
|
6
|
+
} from "./pool.node-chunks/chunk-WX4462A5.js";
|
|
7
7
|
import {
|
|
8
8
|
getAppId,
|
|
9
9
|
getAppName,
|
|
10
10
|
resetStoreInfo
|
|
11
|
-
} from "./pool.node-chunks/chunk-
|
|
11
|
+
} from "./pool.node-chunks/chunk-CKQISGZS.js";
|
|
12
12
|
|
|
13
13
|
// src/stage-worker-node.js
|
|
14
14
|
import { createRequire } from "node:module";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dimina-kit/compiler",
|
|
3
|
-
"version": "0.0.2-dev.
|
|
3
|
+
"version": "0.0.2-dev.20260728065133",
|
|
4
4
|
"description": "dmcc compiler bundles (browser + node) that drive @dimina/compiler against a caller-injected node:fs replacement (no bundled fs)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/parser": "^7.29.7",
|
|
36
|
-
"@vue/compiler-sfc": "^3.5.
|
|
36
|
+
"@vue/compiler-sfc": "^3.5.40",
|
|
37
37
|
"assert": "^2.1.0",
|
|
38
38
|
"autoprefixer": "^10.5.3",
|
|
39
39
|
"buffer": "^6.0.3",
|
|
@@ -43,21 +43,21 @@
|
|
|
43
43
|
"estree-walker": "^3.0.3",
|
|
44
44
|
"events": "^3.3.0",
|
|
45
45
|
"htmlparser2": "^12.0.0",
|
|
46
|
-
"less": "^4.
|
|
46
|
+
"less": "^4.8.1",
|
|
47
47
|
"magic-string": "^0.30.21",
|
|
48
48
|
"memfs": "^4.57.8",
|
|
49
|
-
"oxc-parser": "^0.
|
|
49
|
+
"oxc-parser": "^0.140.0",
|
|
50
50
|
"oxc-walker": "^1.0.0",
|
|
51
51
|
"path-browserify": "^1.0.1",
|
|
52
|
-
"postcss": "^8.5.
|
|
52
|
+
"postcss": "^8.5.23",
|
|
53
53
|
"postcss-selector-parser": "^7.1.4",
|
|
54
|
-
"sass": "^1.
|
|
54
|
+
"sass": "^1.102.0",
|
|
55
55
|
"source-map-js": "^1.2.1",
|
|
56
56
|
"stream-browserify": "^3.0.0",
|
|
57
57
|
"util": "^0.12.5"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@oxc-parser/binding-wasm32-wasi": "^0.
|
|
60
|
+
"@oxc-parser/binding-wasm32-wasi": "^0.140.0",
|
|
61
61
|
"esbuild-wasm": "^0.28.1"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"esbuild-wasm": "^0.28.1"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
|
+
"check:wasm-alignment": "node scripts/check-wasm-alignment.js",
|
|
75
76
|
"build:node": "node scripts/build-compiler.js node",
|
|
76
77
|
"build:browser": "node scripts/build-compiler.js browser",
|
|
77
78
|
"build": "pnpm run build:node && pnpm run build:browser",
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { access, readFile } from 'node:fs/promises'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
|
|
6
|
+
function printUsage() {
|
|
7
|
+
console.log(
|
|
8
|
+
'Usage: node scripts/check-wasm-alignment.js\n\n' +
|
|
9
|
+
'Fails if packages/compiler and upstream @dimina/compiler (dimina submodule,\n' +
|
|
10
|
+
'dimina/fe/packages/compiler) resolve any shared dependency — or the wasm/native\n' +
|
|
11
|
+
'build pairs oxc-parser/@oxc-parser/binding-wasm32-wasi and esbuild/esbuild-wasm —\n' +
|
|
12
|
+
'to a different installed version. Requires both workspaces to be installed\n' +
|
|
13
|
+
'(pnpm install, pnpm -C dimina/fe install).',
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
18
|
+
printUsage()
|
|
19
|
+
process.exit(0)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
23
|
+
const root = path.resolve(__dirname, '..')
|
|
24
|
+
const kitPkgPath = path.join(root, 'package.json')
|
|
25
|
+
const diminaFeRoot = path.resolve(root, '../../dimina/fe')
|
|
26
|
+
const upstreamPkgPath = path.join(diminaFeRoot, 'packages/compiler/package.json')
|
|
27
|
+
|
|
28
|
+
async function readJson(p) {
|
|
29
|
+
return JSON.parse(await readFile(p, 'utf8'))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function exists(p) {
|
|
33
|
+
try {
|
|
34
|
+
await access(p)
|
|
35
|
+
return true
|
|
36
|
+
} catch {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// package.json only records the declared semver *range* (e.g. "^3.5.39");
|
|
42
|
+
// for a dep whose major is >=1 that range also matches later minors
|
|
43
|
+
// installed independently on each side. Walk the actual node_modules
|
|
44
|
+
// resolution each side's own package.json would use, and climb to the
|
|
45
|
+
// nearest package.json whose name matches (not just the first package.json
|
|
46
|
+
// found, which could belong to a nested dependency).
|
|
47
|
+
//
|
|
48
|
+
// requiredPrefix guards the upstream (dimina/fe) side specifically: dimina/fe
|
|
49
|
+
// is nested inside this repo, so if its own node_modules isn't installed,
|
|
50
|
+
// Node's resolution walks up past it and can silently land in kit's own
|
|
51
|
+
// hoisted node_modules — "resolved" would then just be comparing kit against
|
|
52
|
+
// itself and reporting false alignment. Reject any resolution that doesn't
|
|
53
|
+
// land under dimina/fe instead of treating it as a valid answer.
|
|
54
|
+
async function resolveInstalledVersion(anchorPackageJsonPath, depName, requiredPrefix) {
|
|
55
|
+
let entry
|
|
56
|
+
try {
|
|
57
|
+
entry = createRequire(anchorPackageJsonPath).resolve(depName)
|
|
58
|
+
} catch {
|
|
59
|
+
return null
|
|
60
|
+
}
|
|
61
|
+
if (requiredPrefix && !entry.startsWith(requiredPrefix + path.sep)) {
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
let dir = path.dirname(entry)
|
|
65
|
+
for (let hop = 0; hop < 16; hop++) {
|
|
66
|
+
const candidate = path.join(dir, 'package.json')
|
|
67
|
+
if (await exists(candidate)) {
|
|
68
|
+
const pkg = await readJson(candidate)
|
|
69
|
+
if (pkg.name === depName) return pkg.version
|
|
70
|
+
}
|
|
71
|
+
const parent = path.dirname(dir)
|
|
72
|
+
if (parent === dir) break
|
|
73
|
+
dir = parent
|
|
74
|
+
}
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// This package's node/browser bundles are esbuild-driven mirrors of
|
|
79
|
+
// @dimina/compiler (upstream, in the dimina submodule) — same compiler
|
|
80
|
+
// logic against a caller-injected fs. Compare live, not a hardcoded dep
|
|
81
|
+
// list, so a newly-shared dependency is picked up automatically.
|
|
82
|
+
const kitPkg = await readJson(kitPkgPath)
|
|
83
|
+
let upstreamPkg
|
|
84
|
+
try {
|
|
85
|
+
upstreamPkg = await readJson(upstreamPkgPath)
|
|
86
|
+
} catch (err) {
|
|
87
|
+
console.error(
|
|
88
|
+
`check-wasm-alignment: could not read upstream package.json at ${upstreamPkgPath} (${err.message})\n` +
|
|
89
|
+
'The dimina submodule looks uninitialized. Run: git submodule update --init dimina',
|
|
90
|
+
)
|
|
91
|
+
process.exit(2)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Scoped to deps kit itself declares. Packages dmcc source imports but kit
|
|
95
|
+
// doesn't declare (e.g. @vue/shared, pulled in only via compatibility.js)
|
|
96
|
+
// aren't independently resolved by kit at all — kit's esbuild config bundles
|
|
97
|
+
// (inlines) anything not in its NODE_EXTERNAL list straight from the dimina/fe
|
|
98
|
+
// source file that imports it, so that code is always upstream's current
|
|
99
|
+
// install by construction. Drift is only possible for deps kit resolves on
|
|
100
|
+
// its own — i.e. the ones it declares here.
|
|
101
|
+
const kitDeps = { ...kitPkg.dependencies, ...kitPkg.devDependencies }
|
|
102
|
+
const upstreamDeps = { ...upstreamPkg.dependencies }
|
|
103
|
+
|
|
104
|
+
const mismatches = []
|
|
105
|
+
const unresolved = []
|
|
106
|
+
|
|
107
|
+
// Every shared dep here is part of dmcc's actual compile pipeline (e.g.
|
|
108
|
+
// @vue/compiler-sfc's compileStyle/compileTemplate drive CSS scope-hash and
|
|
109
|
+
// template codegen — not a cosmetic tool), so all of them get the same
|
|
110
|
+
// resolved-version check as the wasm toolchain, not just oxc-parser/esbuild.
|
|
111
|
+
// dimina/fe doesn't commit a lockfile (gitignored upstream), so its resolved
|
|
112
|
+
// version can drift from kit's pinned lockfile purely from the passage of
|
|
113
|
+
// time — that drift is exactly what this check exists to catch, not noise
|
|
114
|
+
// to suppress by only comparing the declared specifier string.
|
|
115
|
+
for (const name of Object.keys(kitDeps)) {
|
|
116
|
+
if (!(name in upstreamDeps)) continue
|
|
117
|
+
|
|
118
|
+
const kitVersion = await resolveInstalledVersion(kitPkgPath, name)
|
|
119
|
+
const upstreamVersion = await resolveInstalledVersion(upstreamPkgPath, name, diminaFeRoot)
|
|
120
|
+
if (!kitVersion || !upstreamVersion) {
|
|
121
|
+
unresolved.push(` ${name}: kit=${kitVersion ?? 'unresolved'} upstream=${upstreamVersion ?? 'unresolved'}`)
|
|
122
|
+
continue
|
|
123
|
+
}
|
|
124
|
+
if (kitVersion !== upstreamVersion) {
|
|
125
|
+
mismatches.push(` ${name}: kit resolves ${kitVersion}, upstream(@dimina/compiler) resolves ${upstreamVersion}`)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// The wasm builds of oxc-parser/esbuild are peer/dev deps here (native
|
|
130
|
+
// bindings aren't available in the browser); their version must track the
|
|
131
|
+
// non-wasm package they're a build target of, or the browser bundle can
|
|
132
|
+
// silently run a different parser/bundler version than the node bundle.
|
|
133
|
+
// Both sides of this pair live in kit's own package.json/node_modules, so
|
|
134
|
+
// resolution never depends on dimina/fe being installed.
|
|
135
|
+
const wasmPairs = [
|
|
136
|
+
['oxc-parser', '@oxc-parser/binding-wasm32-wasi'],
|
|
137
|
+
['esbuild', 'esbuild-wasm'],
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
for (const [nativeName, wasmName] of wasmPairs) {
|
|
141
|
+
const nativeVersion = await resolveInstalledVersion(kitPkgPath, nativeName)
|
|
142
|
+
const wasmVersion = await resolveInstalledVersion(kitPkgPath, wasmName)
|
|
143
|
+
if (!nativeVersion || !wasmVersion) {
|
|
144
|
+
unresolved.push(` ${wasmName}/${nativeName}: kit=${nativeVersion ?? 'unresolved'}/${wasmVersion ?? 'unresolved'}`)
|
|
145
|
+
continue
|
|
146
|
+
}
|
|
147
|
+
if (nativeVersion !== wasmVersion) {
|
|
148
|
+
mismatches.push(` ${wasmName} resolves ${wasmVersion}, does not match ${nativeName} resolving ${nativeVersion}`)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (unresolved.length > 0) {
|
|
153
|
+
console.error(
|
|
154
|
+
'check-wasm-alignment: could not resolve installed versions for some shared deps — ' +
|
|
155
|
+
'this proves nothing either way, so treat it as a setup failure, not a pass:\n' +
|
|
156
|
+
unresolved.join('\n') +
|
|
157
|
+
'\nRun: pnpm install && pnpm -C dimina/fe install',
|
|
158
|
+
)
|
|
159
|
+
process.exit(2)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (mismatches.length > 0) {
|
|
163
|
+
console.error(
|
|
164
|
+
'check-wasm-alignment: drift between packages/compiler and upstream @dimina/compiler ' +
|
|
165
|
+
'(dimina submodule) — this package re-implements dmcc against the same toolchain:\n' +
|
|
166
|
+
mismatches.join('\n') +
|
|
167
|
+
'\nRealign the drifted side (bump/pin in package.json, then pnpm install) and rebuild ' +
|
|
168
|
+
'(pnpm --filter @dimina-kit/compiler build).',
|
|
169
|
+
)
|
|
170
|
+
process.exit(1)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
console.log('check-wasm-alignment: packages/compiler deps aligned with upstream @dimina/compiler')
|
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isMainThread,
|
|
3
|
-
parentPort
|
|
4
|
-
} from "./chunk-2VRS523Z.js";
|
|
5
|
-
import {
|
|
6
|
-
collectAssets,
|
|
7
|
-
fs_default,
|
|
8
|
-
getAppId,
|
|
9
|
-
getComponent,
|
|
10
|
-
getContentByPath,
|
|
11
|
-
getStyleExts,
|
|
12
|
-
getTargetPath,
|
|
13
|
-
getWorkPath,
|
|
14
|
-
resetStoreInfo,
|
|
15
|
-
tagWhiteList,
|
|
16
|
-
transformRpx
|
|
17
|
-
} from "./chunk-QVEZ34FP.js";
|
|
18
|
-
|
|
19
|
-
// ../../dimina/fe/packages/compiler/src/core/style-compiler.js
|
|
20
|
-
import path from "node:path";
|
|
21
|
-
import { compileStyle } from "@vue/compiler-sfc";
|
|
22
|
-
import autoprefixer from "autoprefixer";
|
|
23
|
-
import cssnano from "cssnano";
|
|
24
|
-
import less from "less";
|
|
25
|
-
import postcss from "postcss";
|
|
26
|
-
import selectorParser from "postcss-selector-parser";
|
|
27
|
-
import * as sass from "sass";
|
|
28
|
-
var compileRes = /* @__PURE__ */ new Map();
|
|
29
|
-
if (!isMainThread) {
|
|
30
|
-
parentPort.on("message", async ({ pages, storeInfo }) => {
|
|
31
|
-
try {
|
|
32
|
-
resetStoreInfo(storeInfo);
|
|
33
|
-
const progress = {
|
|
34
|
-
_completedTasks: 0,
|
|
35
|
-
get completedTasks() {
|
|
36
|
-
return this._completedTasks;
|
|
37
|
-
},
|
|
38
|
-
set completedTasks(value) {
|
|
39
|
-
this._completedTasks = value;
|
|
40
|
-
parentPort.postMessage({ completedTasks: this._completedTasks });
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
await compileSS(pages.mainPages, null, progress);
|
|
44
|
-
for (const [root, subPages] of Object.entries(pages.subPages)) {
|
|
45
|
-
await compileSS(subPages.info, root, progress);
|
|
46
|
-
}
|
|
47
|
-
compileRes.clear();
|
|
48
|
-
parentPort.postMessage({ success: true });
|
|
49
|
-
} catch (error) {
|
|
50
|
-
compileRes.clear();
|
|
51
|
-
parentPort.postMessage({
|
|
52
|
-
success: false,
|
|
53
|
-
error: {
|
|
54
|
-
message: error.message,
|
|
55
|
-
stack: error.stack,
|
|
56
|
-
name: error.name
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
async function compileSS(pages, root, progress) {
|
|
63
|
-
for (const page of pages) {
|
|
64
|
-
const code = await buildCompileCss(page, /* @__PURE__ */ new Set()) || "";
|
|
65
|
-
const filename = `${page.path.replace(/\//g, "_")}`;
|
|
66
|
-
if (root) {
|
|
67
|
-
const subDir = `${getTargetPath()}/${root}`;
|
|
68
|
-
if (!fs_default.existsSync(subDir)) {
|
|
69
|
-
fs_default.mkdirSync(subDir, { recursive: true });
|
|
70
|
-
}
|
|
71
|
-
fs_default.writeFileSync(`${subDir}/${filename}.css`, code);
|
|
72
|
-
} else {
|
|
73
|
-
const mainDir = `${getTargetPath()}/main`;
|
|
74
|
-
if (!fs_default.existsSync(mainDir)) {
|
|
75
|
-
fs_default.mkdirSync(mainDir, { recursive: true });
|
|
76
|
-
}
|
|
77
|
-
fs_default.writeFileSync(`${mainDir}/${filename}.css`, code);
|
|
78
|
-
}
|
|
79
|
-
progress.completedTasks++;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async function buildCompileCss(module, compiledPaths = /* @__PURE__ */ new Set()) {
|
|
83
|
-
let result = "";
|
|
84
|
-
const pendingModules = [module];
|
|
85
|
-
while (pendingModules.length > 0) {
|
|
86
|
-
const currentModule = pendingModules.pop();
|
|
87
|
-
const currentPath = currentModule.path || currentModule.absolutePath;
|
|
88
|
-
if (compiledPaths.has(currentPath)) {
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
compiledPaths.add(currentPath);
|
|
92
|
-
result += await enhanceCSS(currentModule) || "";
|
|
93
|
-
const componentPaths = Object.values(currentModule.usingComponents || {});
|
|
94
|
-
for (let index = componentPaths.length - 1; index >= 0; index--) {
|
|
95
|
-
const componentModule = getComponent(componentPaths[index]);
|
|
96
|
-
if (componentModule) {
|
|
97
|
-
pendingModules.push(componentModule);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
function boostExternalClassSelectors(cssCode, moduleId) {
|
|
104
|
-
if (!moduleId || !cssCode) {
|
|
105
|
-
return cssCode;
|
|
106
|
-
}
|
|
107
|
-
const scopeAttribute = `data-v-${moduleId}`;
|
|
108
|
-
const externalScopeAttribute = "data-dd-external-class-scope";
|
|
109
|
-
const ast = postcss.parse(cssCode);
|
|
110
|
-
ast.walkRules((rule) => {
|
|
111
|
-
if (!rule.selector.includes(`[${scopeAttribute}]`)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
rule.selector = selectorParser((selectors) => {
|
|
115
|
-
for (const selector of [...selectors.nodes]) {
|
|
116
|
-
const boostedSelector = selector.clone();
|
|
117
|
-
const scopeNodes = [];
|
|
118
|
-
boostedSelector.walkAttributes((attribute) => {
|
|
119
|
-
if (attribute.attribute === scopeAttribute) {
|
|
120
|
-
scopeNodes.push(attribute);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
const targetScope = scopeNodes.at(-1);
|
|
124
|
-
if (!targetScope) {
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
targetScope.parent.insertAfter(targetScope, selectorParser.attribute({
|
|
128
|
-
attribute: externalScopeAttribute,
|
|
129
|
-
operator: "~=",
|
|
130
|
-
quoteMark: '"',
|
|
131
|
-
value: scopeAttribute
|
|
132
|
-
}));
|
|
133
|
-
selectors.append(boostedSelector);
|
|
134
|
-
}
|
|
135
|
-
}).processSync(rule.selector);
|
|
136
|
-
});
|
|
137
|
-
return ast.toResult().css;
|
|
138
|
-
}
|
|
139
|
-
async function enhanceCSS(module) {
|
|
140
|
-
const absolutePath = module.absolutePath ? module.absolutePath : getAbsolutePath(module.path);
|
|
141
|
-
if (!absolutePath) {
|
|
142
|
-
return "";
|
|
143
|
-
}
|
|
144
|
-
const cacheKey = `${absolutePath}::${module.id || ""}`;
|
|
145
|
-
const inputCSS = getContentByPath(absolutePath);
|
|
146
|
-
if (!inputCSS) {
|
|
147
|
-
return "";
|
|
148
|
-
}
|
|
149
|
-
if (compileRes.has(cacheKey)) {
|
|
150
|
-
return compileRes.get(cacheKey);
|
|
151
|
-
}
|
|
152
|
-
let processedCSS = normalizeRootStyleImports(inputCSS);
|
|
153
|
-
const ext = path.extname(absolutePath).toLowerCase();
|
|
154
|
-
try {
|
|
155
|
-
if (ext === ".less") {
|
|
156
|
-
const result2 = await less.render(processedCSS, {
|
|
157
|
-
filename: absolutePath,
|
|
158
|
-
paths: [path.dirname(absolutePath), getWorkPath()]
|
|
159
|
-
});
|
|
160
|
-
processedCSS = result2.css;
|
|
161
|
-
} else if (ext === ".scss" || ext === ".sass") {
|
|
162
|
-
const result2 = sass.compileString(processedCSS, {
|
|
163
|
-
loadPaths: [path.dirname(absolutePath), getWorkPath()],
|
|
164
|
-
syntax: ext === ".sass" ? "indented" : "scss"
|
|
165
|
-
});
|
|
166
|
-
processedCSS = result2.css;
|
|
167
|
-
}
|
|
168
|
-
} catch (error) {
|
|
169
|
-
console.error(`[style] \u9884\u5904\u7406\u5668\u7F16\u8BD1\u5931\u8D25 ${absolutePath}:`, error.message);
|
|
170
|
-
processedCSS = inputCSS;
|
|
171
|
-
}
|
|
172
|
-
const fixedCSS = ensureImportSemicolons(processedCSS);
|
|
173
|
-
let ast;
|
|
174
|
-
try {
|
|
175
|
-
ast = postcss.parse(fixedCSS);
|
|
176
|
-
} catch (error) {
|
|
177
|
-
console.error(`[style] PostCSS \u89E3\u6790\u5931\u8D25 ${absolutePath}:`, error.message);
|
|
178
|
-
return "";
|
|
179
|
-
}
|
|
180
|
-
const promises = [];
|
|
181
|
-
ast.walk(async (node) => {
|
|
182
|
-
if (node.type === "atrule" && node.name === "import") {
|
|
183
|
-
const str = node.params.replace(/^['"]|['"]$/g, "");
|
|
184
|
-
const importFullPath = resolveStyleImportPath(absolutePath, str);
|
|
185
|
-
node.remove();
|
|
186
|
-
promises.push(buildCompileCss({ absolutePath: importFullPath, id: module.id }, /* @__PURE__ */ new Set()));
|
|
187
|
-
} else if (node.type === "rule") {
|
|
188
|
-
if (node.selector.includes("::v-deep")) {
|
|
189
|
-
node.selector = node.selector.replace(/::v-deep\s+(\S[^{]*)/g, ":deep($1)");
|
|
190
|
-
}
|
|
191
|
-
if (node.selector.includes(":host")) {
|
|
192
|
-
node.selector = processHostSelector(node.selector, module.id);
|
|
193
|
-
}
|
|
194
|
-
node.selector = selectorParser((selectors) => {
|
|
195
|
-
selectors.walkTags((tag) => {
|
|
196
|
-
if (tagWhiteList.includes(tag.value)) {
|
|
197
|
-
tag.value = `.dd-${tag.value}`;
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}).processSync(node.selector);
|
|
201
|
-
} else if (node.type === "comment") {
|
|
202
|
-
node.remove();
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
ast.walkDecls((decl) => {
|
|
206
|
-
decl.value = normalizeCssUrlValue(decl.value, absolutePath);
|
|
207
|
-
decl.value = transformRpx(decl.value);
|
|
208
|
-
});
|
|
209
|
-
const cssCode = ast.toResult().css;
|
|
210
|
-
const moduleId = module.id;
|
|
211
|
-
const scopedCode = compileStyle({
|
|
212
|
-
source: cssCode,
|
|
213
|
-
id: moduleId,
|
|
214
|
-
scoped: !!moduleId
|
|
215
|
-
}).code;
|
|
216
|
-
const externalClassCode = boostExternalClassSelectors(scopedCode, moduleId);
|
|
217
|
-
const res = await postcss([
|
|
218
|
-
autoprefixer({ overrideBrowserslist: ["cover 99.5%"] }),
|
|
219
|
-
cssnano()
|
|
220
|
-
]).process(externalClassCode, { from: void 0 });
|
|
221
|
-
const importCss = (await Promise.all(promises)).filter(Boolean).join("");
|
|
222
|
-
const result = importCss + res.css;
|
|
223
|
-
compileRes.set(cacheKey, result);
|
|
224
|
-
return result;
|
|
225
|
-
}
|
|
226
|
-
function normalizeCssUrlValue(value, absolutePath) {
|
|
227
|
-
return value.replace(/url\(([^)]+)\)/g, (fullMatch, rawUrl) => {
|
|
228
|
-
const cleanedUrl = rawUrl.trim().replace(/^['"]|['"]$/g, "");
|
|
229
|
-
if (!cleanedUrl || cleanedUrl.startsWith("data:image")) {
|
|
230
|
-
return fullMatch;
|
|
231
|
-
}
|
|
232
|
-
if (cleanedUrl.startsWith("//")) {
|
|
233
|
-
return `url(https:${cleanedUrl})`;
|
|
234
|
-
}
|
|
235
|
-
if (/^(https?:|blob:|data:)/.test(cleanedUrl)) {
|
|
236
|
-
return fullMatch;
|
|
237
|
-
}
|
|
238
|
-
const realSrc = collectAssets(getWorkPath(), absolutePath, cleanedUrl, getTargetPath(), getAppId());
|
|
239
|
-
return `url(${realSrc})`;
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
function getAbsolutePath(modulePath) {
|
|
243
|
-
const workPath = getWorkPath();
|
|
244
|
-
const src = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
|
|
245
|
-
for (const ssType of getStyleExts()) {
|
|
246
|
-
const ssFullPath = `${workPath}${src}${ssType}`;
|
|
247
|
-
if (fs_default.existsSync(ssFullPath)) {
|
|
248
|
-
return ssFullPath;
|
|
249
|
-
}
|
|
250
|
-
const indexSsFullPath = `${workPath}${src}/index${ssType}`;
|
|
251
|
-
if (fs_default.existsSync(indexSsFullPath)) {
|
|
252
|
-
return indexSsFullPath;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
function resolveStyleImportPath(absolutePath, importPath, workPath = getWorkPath()) {
|
|
257
|
-
if (importPath.startsWith("/")) {
|
|
258
|
-
return path.join(workPath, importPath);
|
|
259
|
-
}
|
|
260
|
-
return path.resolve(path.dirname(absolutePath), importPath);
|
|
261
|
-
}
|
|
262
|
-
function normalizeRootStyleImports(source, workPath = getWorkPath()) {
|
|
263
|
-
return source.replace(/(@import\s+(?:\(.*?\)\s*)?(?:url\()?['"])(\/[^'")]+)(['"]\)?)/g, (_, prefix, importPath, suffix) => {
|
|
264
|
-
return `${prefix}${path.join(workPath, importPath)}${suffix}`;
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
function ensureImportSemicolons(css) {
|
|
268
|
-
return css.replace(/@import[^;\n]*$/gm, (match) => {
|
|
269
|
-
return match.endsWith(";") ? match : `${match};`;
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
function processHostSelector(selector, moduleId) {
|
|
273
|
-
const hostSelector = `[data-dd-style-host~="${moduleId}"]`;
|
|
274
|
-
return selector.replace(/:host\(([^)]+)\)/g, `${hostSelector}$1`).replace(/:host(?![\w-])/g, hostSelector);
|
|
275
|
-
}
|
|
276
|
-
function __resetStyleState() {
|
|
277
|
-
compileRes.clear();
|
|
278
|
-
}
|
|
279
|
-
export {
|
|
280
|
-
__resetStyleState,
|
|
281
|
-
boostExternalClassSelectors,
|
|
282
|
-
compileSS,
|
|
283
|
-
ensureImportSemicolons,
|
|
284
|
-
normalizeCssUrlValue,
|
|
285
|
-
normalizeRootStyleImports,
|
|
286
|
-
processHostSelector,
|
|
287
|
-
resolveStyleImportPath
|
|
288
|
-
};
|