carbon-preprocess-svelte 0.11.18 → 0.11.20
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.
|
@@ -9,6 +9,9 @@ const magic_string_1 = __importDefault(require("magic-string"));
|
|
|
9
9
|
const compiler_1 = require("svelte/compiler");
|
|
10
10
|
const component_index_1 = require("../component-index");
|
|
11
11
|
const constants_1 = require("../constants");
|
|
12
|
+
const NODE_MODULES_REGEX = /node_modules/;
|
|
13
|
+
const SCRIPT_OPEN_TAG_REGEX = /^<script lang="ts">/;
|
|
14
|
+
const SCRIPT_CLOSE_TAG_REGEX = /<\/script>$/;
|
|
12
15
|
function rewriteImport(s, node, map) {
|
|
13
16
|
let content = "";
|
|
14
17
|
for (const specifier of node.specifiers) {
|
|
@@ -27,7 +30,7 @@ const optimizeImports = () => {
|
|
|
27
30
|
// Skip files in node_modules to minimize unnecessary preprocessing
|
|
28
31
|
if (!filename)
|
|
29
32
|
return;
|
|
30
|
-
if (
|
|
33
|
+
if (NODE_MODULES_REGEX.test(filename))
|
|
31
34
|
return;
|
|
32
35
|
// Wrap the content in a `<script>` tag to parse it with the Svelte parser.
|
|
33
36
|
const content = `<script lang="ts">${raw}</script>`;
|
|
@@ -40,9 +43,12 @@ const optimizeImports = () => {
|
|
|
40
43
|
case constants_1.CarbonSvelte.Components:
|
|
41
44
|
rewriteImport(s, node, ({ imported, local }) => {
|
|
42
45
|
var _a;
|
|
46
|
+
// Use index if available for backwards compatibility with special paths, like .js files.
|
|
47
|
+
// Otherwise, use optimistic path for new components.
|
|
43
48
|
const import_path = (_a = component_index_1.components[imported.name]) === null || _a === void 0 ? void 0 : _a.path;
|
|
44
|
-
if (!import_path)
|
|
45
|
-
return ""
|
|
49
|
+
if (!import_path) {
|
|
50
|
+
return `import ${local.name} from "${import_name}/src/${imported.name}/${imported.name}.svelte";`;
|
|
51
|
+
}
|
|
46
52
|
return `import ${local.name} from "${import_path}";`;
|
|
47
53
|
});
|
|
48
54
|
break;
|
|
@@ -56,8 +62,8 @@ const optimizeImports = () => {
|
|
|
56
62
|
}
|
|
57
63
|
},
|
|
58
64
|
});
|
|
59
|
-
s.replace(
|
|
60
|
-
s.replace(
|
|
65
|
+
s.replace(SCRIPT_OPEN_TAG_REGEX, "");
|
|
66
|
+
s.replace(SCRIPT_CLOSE_TAG_REGEX, "");
|
|
61
67
|
return {
|
|
62
68
|
code: s.toString(),
|
|
63
69
|
map: s.generateMap({ source: filename, hires: true }),
|