@neuxnet/neux-cli 0.2.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/README.md +438 -0
- package/README.zh-CN.md +554 -0
- package/assets/container/assets/index.css +1 -0
- package/assets/container/assets/index.js +137 -0
- package/assets/container/assets/pageFrame.css +1 -0
- package/assets/container/assets/pageFrame.js +56 -0
- package/assets/container/assets/service.js +6 -0
- package/assets/container/assets/vconsole.js +931 -0
- package/assets/container/favicon.ico +0 -0
- package/assets/container/images/icon-arrow.png +0 -0
- package/assets/container/images/mini-action-white.png +0 -0
- package/assets/container/images/mini-action.png +0 -0
- package/assets/container/images/mini-arrow-left-white.png +0 -0
- package/assets/container/images/mini-arrow-left.jpg +0 -0
- package/assets/container/images/mini-arrow-left.png +0 -0
- package/assets/container/images/mini-close-white.png +0 -0
- package/assets/container/images/mini-close.png +0 -0
- package/assets/container/images/more.png +0 -0
- package/assets/container/images/search.jpg +0 -0
- package/assets/container/index.html +1 -0
- package/assets/container/pageFrame.html +1 -0
- package/assets/init/tabbar/home-active.png +0 -0
- package/assets/init/tabbar/home.png +0 -0
- package/assets/init/tabbar/list-active.png +0 -0
- package/assets/init/tabbar/list.png +0 -0
- package/assets/init/types/neux-api.d.ts +1402 -0
- package/package.json +68 -0
- package/scripts/generate-init-types.js +210 -0
- package/scripts/sync-compiler.js +22 -0
- package/scripts/sync-web-container.js +34 -0
- package/src/bin/cli.js +646 -0
- package/src/core/brand.js +11 -0
- package/src/core/compiler.js +305 -0
- package/src/core/defaults.js +12 -0
- package/src/core/dev.js +15 -0
- package/src/core/errors.js +17 -0
- package/src/core/fs.js +66 -0
- package/src/core/i18n.js +37 -0
- package/src/core/init.js +866 -0
- package/src/core/lifecycle.js +32 -0
- package/src/core/manifest.js +72 -0
- package/src/core/pack.js +156 -0
- package/src/core/package-info.js +27 -0
- package/src/core/preview-server.js +123 -0
- package/src/core/project.js +101 -0
- package/src/core/prompts.js +71 -0
- package/src/core/proxy-security.js +141 -0
- package/src/core/proxy.js +156 -0
- package/src/core/qr.js +41 -0
- package/src/core/terminal-qr.js +72 -0
- package/src/core/update.js +278 -0
- package/src/core/watch.js +113 -0
- package/src/core/web.js +649 -0
- package/src/core/zip.js +120 -0
- package/src/index.js +20 -0
- package/src/providers/service-client.js +149 -0
- package/src/providers/service-config.js +264 -0
- package/src/providers/service.js +146 -0
- package/src/providers/upload.js +112 -0
- package/vendor/dimina-compiler/bin/index.cjs +265 -0
- package/vendor/dimina-compiler/bin/index.js +263 -0
- package/vendor/dimina-compiler/compatibility-B-DoZtUX.cjs +395 -0
- package/vendor/dimina-compiler/compatibility-Cl3-DO6V.js +366 -0
- package/vendor/dimina-compiler/core/logic-compiler.cjs +378 -0
- package/vendor/dimina-compiler/core/logic-compiler.js +374 -0
- package/vendor/dimina-compiler/core/style-compiler.cjs +392 -0
- package/vendor/dimina-compiler/core/style-compiler.js +377 -0
- package/vendor/dimina-compiler/core/view-compiler.cjs +1601 -0
- package/vendor/dimina-compiler/core/view-compiler.js +1582 -0
- package/vendor/dimina-compiler/index.cjs +762 -0
- package/vendor/dimina-compiler/index.js +751 -0
- package/vendor/dimina-compiler/sourcemap-BgtIgqkC.cjs +1377 -0
- package/vendor/dimina-compiler/sourcemap-CKjhV9h7.js +1135 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sourcemap = require("../sourcemap-BgtIgqkC.cjs");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
node_fs = require_sourcemap.__toESM(node_fs, 1);
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_sourcemap.__toESM(node_path, 1);
|
|
7
|
+
let node_url = require("node:url");
|
|
8
|
+
let node_worker_threads = require("node:worker_threads");
|
|
9
|
+
let _vue_compiler_sfc = require("@vue/compiler-sfc");
|
|
10
|
+
let autoprefixer = require("autoprefixer");
|
|
11
|
+
autoprefixer = require_sourcemap.__toESM(autoprefixer, 1);
|
|
12
|
+
let cssnano = require("cssnano");
|
|
13
|
+
cssnano = require_sourcemap.__toESM(cssnano, 1);
|
|
14
|
+
let less = require("less");
|
|
15
|
+
less = require_sourcemap.__toESM(less, 1);
|
|
16
|
+
let postcss = require("postcss");
|
|
17
|
+
postcss = require_sourcemap.__toESM(postcss, 1);
|
|
18
|
+
let postcss_selector_parser = require("postcss-selector-parser");
|
|
19
|
+
postcss_selector_parser = require_sourcemap.__toESM(postcss_selector_parser, 1);
|
|
20
|
+
let sass = require("sass");
|
|
21
|
+
sass = require_sourcemap.__toESM(sass, 1);
|
|
22
|
+
//#region src/core/style-compiler.js
|
|
23
|
+
var compileRes = /* @__PURE__ */ new Map();
|
|
24
|
+
if (!node_worker_threads.isMainThread) node_worker_threads.parentPort.on("message", async ({ pages, storeInfo, sourcemap }) => {
|
|
25
|
+
try {
|
|
26
|
+
require_sourcemap.resetStoreInfo(storeInfo);
|
|
27
|
+
const progress = {
|
|
28
|
+
_completedTasks: 0,
|
|
29
|
+
get completedTasks() {
|
|
30
|
+
return this._completedTasks;
|
|
31
|
+
},
|
|
32
|
+
set completedTasks(value) {
|
|
33
|
+
this._completedTasks = value;
|
|
34
|
+
node_worker_threads.parentPort.postMessage({ completedTasks: this._completedTasks });
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
await compileSS(pages.mainPages, null, progress, { sourcemap });
|
|
38
|
+
for (const [root, subPages] of Object.entries(pages.subPages)) await compileSS(subPages.info, root, progress, { sourcemap });
|
|
39
|
+
compileRes.clear();
|
|
40
|
+
node_worker_threads.parentPort.postMessage({
|
|
41
|
+
success: true,
|
|
42
|
+
dependencyGraph: require_sourcemap.getDependencyGraph().toJSON()
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
compileRes.clear();
|
|
46
|
+
node_worker_threads.parentPort.postMessage({
|
|
47
|
+
success: false,
|
|
48
|
+
error: {
|
|
49
|
+
message: error.message,
|
|
50
|
+
stack: error.stack,
|
|
51
|
+
name: error.name,
|
|
52
|
+
file: error.file,
|
|
53
|
+
line: error.line,
|
|
54
|
+
column: error.column,
|
|
55
|
+
stage: error.stage
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* 编译样式文件
|
|
62
|
+
*/
|
|
63
|
+
async function compileSS(pages, root, progress, options = {}) {
|
|
64
|
+
for (const page of pages) {
|
|
65
|
+
const result = await buildCompileCss(page, /* @__PURE__ */ new Set(), options);
|
|
66
|
+
let code = result.code;
|
|
67
|
+
const filename = `${page.path.replace(/\//g, "_")}`;
|
|
68
|
+
const outputDir = root ? `${require_sourcemap.getTargetPath()}/${root}` : `${require_sourcemap.getTargetPath()}/main`;
|
|
69
|
+
if (!node_fs.default.existsSync(outputDir)) node_fs.default.mkdirSync(outputDir, { recursive: true });
|
|
70
|
+
if (options.sourcemap) {
|
|
71
|
+
const mapFileName = `${filename}.css.map`;
|
|
72
|
+
const map = JSON.parse(result.map);
|
|
73
|
+
map.file = `${filename}.css`;
|
|
74
|
+
code += `\n/*# sourceMappingURL=${mapFileName} */\n`;
|
|
75
|
+
node_fs.default.writeFileSync(`${outputDir}/${mapFileName}`, JSON.stringify(map));
|
|
76
|
+
}
|
|
77
|
+
node_fs.default.writeFileSync(`${outputDir}/${filename}.css`, code);
|
|
78
|
+
progress.completedTasks++;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function buildCompileCss(module, compiledPaths = /* @__PURE__ */ new Set(), options = {}) {
|
|
82
|
+
const chunks = [];
|
|
83
|
+
const pendingModules = [module];
|
|
84
|
+
while (pendingModules.length > 0) {
|
|
85
|
+
const currentModule = pendingModules.pop();
|
|
86
|
+
const currentPath = currentModule.path || currentModule.absolutePath;
|
|
87
|
+
if (compiledPaths.has(currentPath)) continue;
|
|
88
|
+
compiledPaths.add(currentPath);
|
|
89
|
+
const result = await enhanceCSS(currentModule, options);
|
|
90
|
+
if (result.code) chunks.push(result);
|
|
91
|
+
const graphDependencies = require_sourcemap.getDependencyGraph().getDirectDependencies(currentPath, "component");
|
|
92
|
+
const componentPaths = graphDependencies.length > 0 ? graphDependencies : Object.values(currentModule.usingComponents || {});
|
|
93
|
+
for (let index = componentPaths.length - 1; index >= 0; index--) {
|
|
94
|
+
const componentModule = require_sourcemap.getComponent(componentPaths[index]);
|
|
95
|
+
if (componentModule) pendingModules.push(componentModule);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (options.sourcemap) {
|
|
99
|
+
const { code, sourcemap: map } = require_sourcemap.concatSourcemap(chunks);
|
|
100
|
+
return {
|
|
101
|
+
code,
|
|
102
|
+
map
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
code: chunks.map((chunk) => chunk.code).join(""),
|
|
107
|
+
map: null
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function createExternalClassPlugin(moduleId) {
|
|
111
|
+
const scopeAttribute = `data-v-${moduleId}`;
|
|
112
|
+
const externalScopeAttribute = "data-dd-external-class-scope";
|
|
113
|
+
const processedRules = /* @__PURE__ */ new WeakSet();
|
|
114
|
+
return {
|
|
115
|
+
postcssPlugin: "dimina-external-class",
|
|
116
|
+
Rule(rule) {
|
|
117
|
+
if (processedRules.has(rule) || !moduleId || !rule.selector.includes(`[${scopeAttribute}]`)) return;
|
|
118
|
+
processedRules.add(rule);
|
|
119
|
+
try {
|
|
120
|
+
rule.selector = (0, postcss_selector_parser.default)((selectors) => {
|
|
121
|
+
for (const selector of [...selectors.nodes]) {
|
|
122
|
+
const boostedSelector = selector.clone();
|
|
123
|
+
const scopeNodes = [];
|
|
124
|
+
boostedSelector.walkAttributes((attribute) => {
|
|
125
|
+
if (attribute.attribute === scopeAttribute) scopeNodes.push(attribute);
|
|
126
|
+
});
|
|
127
|
+
const targetScope = scopeNodes.at(-1);
|
|
128
|
+
if (!targetScope) continue;
|
|
129
|
+
targetScope.parent.insertAfter(targetScope, postcss_selector_parser.default.attribute({
|
|
130
|
+
attribute: externalScopeAttribute,
|
|
131
|
+
operator: "~=",
|
|
132
|
+
quoteMark: "\"",
|
|
133
|
+
value: scopeAttribute
|
|
134
|
+
}));
|
|
135
|
+
selectors.append(boostedSelector);
|
|
136
|
+
}
|
|
137
|
+
}).processSync(rule.selector);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
throw rule.error(error.message, { plugin: "dimina-external-class" });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function boostExternalClassSelectors(cssCode, moduleId) {
|
|
145
|
+
if (!moduleId || !cssCode) return cssCode;
|
|
146
|
+
return (0, postcss.default)([createExternalClassPlugin(moduleId)]).process(cssCode, { from: void 0 }).css;
|
|
147
|
+
}
|
|
148
|
+
function getStyleSourcePath(absolutePath) {
|
|
149
|
+
const workPath = require_sourcemap.getWorkPath();
|
|
150
|
+
if (absolutePath === workPath || absolutePath.startsWith(`${workPath}${node_path.default.sep}`)) return `/${node_path.default.relative(workPath, absolutePath).split(node_path.default.sep).join("/")}`;
|
|
151
|
+
return absolutePath.split(node_path.default.sep).join("/");
|
|
152
|
+
}
|
|
153
|
+
function createStyleCompileError(stage, absolutePath, cause) {
|
|
154
|
+
if (cause?.name === "StyleCompileError") return cause;
|
|
155
|
+
const line = cause?.line ?? (Number.isInteger(cause?.span?.start?.line) ? cause.span.start.line + 1 : void 0);
|
|
156
|
+
const column = cause?.column ?? (Number.isInteger(cause?.span?.start?.column) ? cause.span.start.column + 1 : void 0);
|
|
157
|
+
const file = getStyleSourcePath(absolutePath);
|
|
158
|
+
const location = line == null ? file : `${file}:${line}${column == null ? "" : `:${column}`}`;
|
|
159
|
+
const reason = cause?.reason || cause?.sassMessage || cause?.message || String(cause);
|
|
160
|
+
const error = new Error(`[style:${stage}] ${location} ${reason}`, { cause });
|
|
161
|
+
error.name = "StyleCompileError";
|
|
162
|
+
error.file = file;
|
|
163
|
+
error.line = line;
|
|
164
|
+
error.column = column;
|
|
165
|
+
error.stage = stage;
|
|
166
|
+
return error;
|
|
167
|
+
}
|
|
168
|
+
function normalizePreprocessorMap(inputMap, absolutePath, inputCSS) {
|
|
169
|
+
const map = typeof inputMap === "string" ? JSON.parse(inputMap) : structuredClone(inputMap);
|
|
170
|
+
const sourcePaths = map.sources.map((source) => {
|
|
171
|
+
let resolvedPath = source;
|
|
172
|
+
if (source.startsWith("file:")) resolvedPath = (0, node_url.fileURLToPath)(source);
|
|
173
|
+
else if (!node_path.default.isAbsolute(source)) resolvedPath = node_path.default.resolve(node_path.default.dirname(absolutePath), source);
|
|
174
|
+
return resolvedPath;
|
|
175
|
+
});
|
|
176
|
+
map.sources = sourcePaths.map(getStyleSourcePath);
|
|
177
|
+
map.sourcesContent = map.sources.map((_, index) => {
|
|
178
|
+
if (sourcePaths[index] === absolutePath) return inputCSS;
|
|
179
|
+
return map.sourcesContent?.[index] ?? null;
|
|
180
|
+
});
|
|
181
|
+
return map;
|
|
182
|
+
}
|
|
183
|
+
function getPostcssMapOptions(sourcemap, prev) {
|
|
184
|
+
if (!sourcemap) return false;
|
|
185
|
+
return {
|
|
186
|
+
inline: false,
|
|
187
|
+
annotation: false,
|
|
188
|
+
sourcesContent: true,
|
|
189
|
+
prev
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function createStyleTransformPlugin(module, absolutePath, importResults, options) {
|
|
193
|
+
const processedRules = /* @__PURE__ */ new WeakSet();
|
|
194
|
+
return {
|
|
195
|
+
postcssPlugin: "dimina-style-transform",
|
|
196
|
+
AtRule(node) {
|
|
197
|
+
if (node.name !== "import") return;
|
|
198
|
+
const importFullPath = resolveStyleImportPath(absolutePath, node.params.replace(/^['"]|['"]$/g, ""));
|
|
199
|
+
node.remove();
|
|
200
|
+
importResults.push(buildCompileCss({
|
|
201
|
+
absolutePath: importFullPath,
|
|
202
|
+
id: module.id,
|
|
203
|
+
ownerPath: module.ownerPath || module.path
|
|
204
|
+
}, /* @__PURE__ */ new Set(), options));
|
|
205
|
+
},
|
|
206
|
+
Rule(rule) {
|
|
207
|
+
if (processedRules.has(rule)) return;
|
|
208
|
+
processedRules.add(rule);
|
|
209
|
+
if (rule.selector.includes("::v-deep")) rule.selector = rule.selector.replace(/::v-deep\s+(\S[^{]*)/g, ":deep($1)");
|
|
210
|
+
if (rule.selector.includes(":host")) rule.selector = processHostSelector(rule.selector, module.id);
|
|
211
|
+
try {
|
|
212
|
+
rule.selector = (0, postcss_selector_parser.default)((selectors) => {
|
|
213
|
+
selectors.walkTags((tag) => {
|
|
214
|
+
if (require_sourcemap.tagWhiteList.includes(tag.value)) tag.value = `.dd-${tag.value}`;
|
|
215
|
+
});
|
|
216
|
+
}).processSync(rule.selector);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
throw rule.error(error.message, { plugin: "dimina-style-transform" });
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
Comment(comment) {
|
|
222
|
+
comment.remove();
|
|
223
|
+
},
|
|
224
|
+
Declaration(declaration) {
|
|
225
|
+
declaration.value = normalizeCssUrlValue(declaration.value, absolutePath, module.ownerPath || module.path);
|
|
226
|
+
declaration.value = require_sourcemap.transformRpx(declaration.value);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
async function enhanceCSS(module, options = {}) {
|
|
231
|
+
const absolutePath = module.absolutePath ? module.absolutePath : getAbsolutePath(module.path);
|
|
232
|
+
if (!absolutePath) return {
|
|
233
|
+
code: "",
|
|
234
|
+
map: null
|
|
235
|
+
};
|
|
236
|
+
const graphOwnerPath = module.ownerPath || module.path;
|
|
237
|
+
if (graphOwnerPath) require_sourcemap.getDependencyGraph().addFile(graphOwnerPath, absolutePath, "style");
|
|
238
|
+
const cacheKey = `${absolutePath}::${module.id || ""}::${options.sourcemap ? "map" : "plain"}`;
|
|
239
|
+
const inputCSS = require_sourcemap.getContentByPath(absolutePath);
|
|
240
|
+
if (!inputCSS) return {
|
|
241
|
+
code: "",
|
|
242
|
+
map: null
|
|
243
|
+
};
|
|
244
|
+
if (compileRes.has(cacheKey)) return compileRes.get(cacheKey);
|
|
245
|
+
let processedCSS = normalizeRootStyleImports(inputCSS);
|
|
246
|
+
let processedMap = options.sourcemap ? require_sourcemap.createLineSourcemap(processedCSS, getStyleSourcePath(absolutePath), inputCSS) : null;
|
|
247
|
+
const ext = node_path.default.extname(absolutePath).toLowerCase();
|
|
248
|
+
try {
|
|
249
|
+
if (ext === ".less") {
|
|
250
|
+
const result = await less.default.render(processedCSS, {
|
|
251
|
+
filename: absolutePath,
|
|
252
|
+
paths: [node_path.default.dirname(absolutePath), require_sourcemap.getWorkPath()],
|
|
253
|
+
sourceMap: options.sourcemap ? {
|
|
254
|
+
outputSourceFiles: true,
|
|
255
|
+
disableSourcemapAnnotation: true
|
|
256
|
+
} : void 0
|
|
257
|
+
});
|
|
258
|
+
processedCSS = result.css;
|
|
259
|
+
if (options.sourcemap) processedMap = normalizePreprocessorMap(result.map, absolutePath, inputCSS);
|
|
260
|
+
} else if (ext === ".scss" || ext === ".sass") {
|
|
261
|
+
const result = sass.compileString(processedCSS, {
|
|
262
|
+
loadPaths: [node_path.default.dirname(absolutePath), require_sourcemap.getWorkPath()],
|
|
263
|
+
syntax: ext === ".sass" ? "indented" : "scss",
|
|
264
|
+
url: options.sourcemap ? (0, node_url.pathToFileURL)(absolutePath) : void 0,
|
|
265
|
+
sourceMap: !!options.sourcemap,
|
|
266
|
+
sourceMapIncludeSources: !!options.sourcemap
|
|
267
|
+
});
|
|
268
|
+
processedCSS = result.css;
|
|
269
|
+
if (options.sourcemap) processedMap = normalizePreprocessorMap(result.sourceMap, absolutePath, inputCSS);
|
|
270
|
+
}
|
|
271
|
+
} catch (error) {
|
|
272
|
+
throw createStyleCompileError("preprocess", absolutePath, error);
|
|
273
|
+
}
|
|
274
|
+
const fixedCSS = ensureImportSemicolons(processedCSS);
|
|
275
|
+
if (options.sourcemap && fixedCSS !== processedCSS) processedMap = require_sourcemap.remapSourcemap(require_sourcemap.createLineSourcemap(fixedCSS, absolutePath, processedCSS), processedMap);
|
|
276
|
+
const importResults = [];
|
|
277
|
+
let transformedResult;
|
|
278
|
+
try {
|
|
279
|
+
transformedResult = await (0, postcss.default)([createStyleTransformPlugin(module, absolutePath, importResults, options)]).process(fixedCSS, {
|
|
280
|
+
from: void 0,
|
|
281
|
+
map: getPostcssMapOptions(options.sourcemap, processedMap)
|
|
282
|
+
});
|
|
283
|
+
} catch (error) {
|
|
284
|
+
throw createStyleCompileError("transform", absolutePath, error);
|
|
285
|
+
}
|
|
286
|
+
const moduleId = module.id;
|
|
287
|
+
let scopedResult;
|
|
288
|
+
try {
|
|
289
|
+
scopedResult = (0, _vue_compiler_sfc.compileStyle)({
|
|
290
|
+
source: transformedResult.css,
|
|
291
|
+
filename: getStyleSourcePath(absolutePath),
|
|
292
|
+
id: moduleId,
|
|
293
|
+
scoped: !!moduleId,
|
|
294
|
+
inMap: options.sourcemap ? transformedResult.map.toJSON() : void 0
|
|
295
|
+
});
|
|
296
|
+
if (scopedResult.errors.length > 0) throw scopedResult.errors[0];
|
|
297
|
+
} catch (error) {
|
|
298
|
+
throw createStyleCompileError("scope", absolutePath, error);
|
|
299
|
+
}
|
|
300
|
+
let externalResult;
|
|
301
|
+
try {
|
|
302
|
+
externalResult = await (0, postcss.default)([createExternalClassPlugin(moduleId)]).process(scopedResult.code, {
|
|
303
|
+
from: void 0,
|
|
304
|
+
map: getPostcssMapOptions(options.sourcemap, scopedResult.map)
|
|
305
|
+
});
|
|
306
|
+
} catch (error) {
|
|
307
|
+
throw createStyleCompileError("external-class", absolutePath, error);
|
|
308
|
+
}
|
|
309
|
+
let finalResult;
|
|
310
|
+
try {
|
|
311
|
+
finalResult = await (0, postcss.default)([(0, autoprefixer.default)({ overrideBrowserslist: ["cover 99.5%"] }), (0, cssnano.default)()]).process(externalResult.css, {
|
|
312
|
+
from: void 0,
|
|
313
|
+
map: getPostcssMapOptions(options.sourcemap, externalResult.map?.toJSON())
|
|
314
|
+
});
|
|
315
|
+
} catch (error) {
|
|
316
|
+
throw createStyleCompileError("postprocess", absolutePath, error);
|
|
317
|
+
}
|
|
318
|
+
const importedChunks = (await Promise.all(importResults)).filter((result) => result.code);
|
|
319
|
+
let result;
|
|
320
|
+
if (options.sourcemap) {
|
|
321
|
+
const { code, sourcemap: map } = require_sourcemap.concatSourcemap([...importedChunks, {
|
|
322
|
+
code: finalResult.css,
|
|
323
|
+
map: finalResult.map.toString()
|
|
324
|
+
}]);
|
|
325
|
+
result = {
|
|
326
|
+
code,
|
|
327
|
+
map
|
|
328
|
+
};
|
|
329
|
+
} else result = {
|
|
330
|
+
code: importedChunks.map((chunk) => chunk.code).join("") + finalResult.css,
|
|
331
|
+
map: null
|
|
332
|
+
};
|
|
333
|
+
compileRes.set(cacheKey, result);
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
function normalizeCssUrlValue(value, absolutePath, graphOwnerPath) {
|
|
337
|
+
return value.replace(/url\(([^)]+)\)/g, (fullMatch, rawUrl) => {
|
|
338
|
+
const cleanedUrl = rawUrl.trim().replace(/^['"]|['"]$/g, "");
|
|
339
|
+
if (!cleanedUrl || cleanedUrl.startsWith("data:image")) return fullMatch;
|
|
340
|
+
if (cleanedUrl.startsWith("//")) return `url(https:${cleanedUrl})`;
|
|
341
|
+
if (/^(https?:|blob:|data:)/.test(cleanedUrl)) return fullMatch;
|
|
342
|
+
if (graphOwnerPath && /\.(?:png|jpe?g|gif|svg)(?:\?.*)?$/.test(cleanedUrl)) require_sourcemap.getDependencyGraph().addFile(graphOwnerPath, require_sourcemap.resolveAssetSourcePath(require_sourcemap.getWorkPath(), absolutePath, cleanedUrl), "style");
|
|
343
|
+
return `url(${require_sourcemap.collectAssets(require_sourcemap.getWorkPath(), absolutePath, cleanedUrl, require_sourcemap.getTargetPath(), require_sourcemap.getAppId())})`;
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function getAbsolutePath(modulePath) {
|
|
347
|
+
const workPath = require_sourcemap.getWorkPath();
|
|
348
|
+
const src = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
|
|
349
|
+
for (const ssType of require_sourcemap.getStyleExts()) {
|
|
350
|
+
const ssFullPath = `${workPath}${src}${ssType}`;
|
|
351
|
+
if (node_fs.default.existsSync(ssFullPath)) return ssFullPath;
|
|
352
|
+
const indexSsFullPath = `${workPath}${src}/index${ssType}`;
|
|
353
|
+
if (node_fs.default.existsSync(indexSsFullPath)) return indexSsFullPath;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function resolveStyleImportPath(absolutePath, importPath, workPath = require_sourcemap.getWorkPath()) {
|
|
357
|
+
if (importPath.startsWith("/")) return node_path.default.join(workPath, importPath);
|
|
358
|
+
return node_path.default.resolve(node_path.default.dirname(absolutePath), importPath);
|
|
359
|
+
}
|
|
360
|
+
function normalizeRootStyleImports(source, workPath = require_sourcemap.getWorkPath()) {
|
|
361
|
+
return source.replace(/(@import\s+(?:\(.*?\)\s*)?(?:url\()?['"])(\/[^'")]+)(['"]\)?)/g, (_, prefix, importPath, suffix) => {
|
|
362
|
+
return `${prefix}${node_path.default.join(workPath, importPath)}${suffix}`;
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Ensures that all @import statements in CSS end with semicolons
|
|
367
|
+
* @param {string} css - The CSS content to process
|
|
368
|
+
* @returns {string} - The processed CSS with semicolons added to @import statements as needed
|
|
369
|
+
*/
|
|
370
|
+
function ensureImportSemicolons(css) {
|
|
371
|
+
return css.replace(/@import[^;\n]*$/gm, (match) => {
|
|
372
|
+
return match.endsWith(";") ? match : `${match};`;
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* 处理 :host 选择器,将其转换为适合组件根节点的选择器
|
|
377
|
+
* @param {string} selector - 包含 :host 的选择器
|
|
378
|
+
* @param {string} moduleId - 组件的模块ID
|
|
379
|
+
* @returns {string} - 转换后的选择器
|
|
380
|
+
*/
|
|
381
|
+
function processHostSelector(selector, moduleId) {
|
|
382
|
+
const hostSelector = `[data-dd-style-host~="${moduleId}"]`;
|
|
383
|
+
return selector.replace(/:host\(([^)]+)\)/g, `${hostSelector}$1`).replace(/:host(?![\w-])/g, hostSelector);
|
|
384
|
+
}
|
|
385
|
+
//#endregion
|
|
386
|
+
exports.boostExternalClassSelectors = boostExternalClassSelectors;
|
|
387
|
+
exports.compileSS = compileSS;
|
|
388
|
+
exports.ensureImportSemicolons = ensureImportSemicolons;
|
|
389
|
+
exports.normalizeCssUrlValue = normalizeCssUrlValue;
|
|
390
|
+
exports.normalizeRootStyleImports = normalizeRootStyleImports;
|
|
391
|
+
exports.processHostSelector = processHostSelector;
|
|
392
|
+
exports.resolveStyleImportPath = resolveStyleImportPath;
|