mappel 0.3.0 → 0.4.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/package.json +1 -1
- package/src/index.mjs +15 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mappel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "generate the import map a page needs from a workspace: resolves every transitive subpath through each package exports map, in layers that compose",
|
|
6
6
|
"type": "module",
|
package/src/index.mjs
CHANGED
|
@@ -49,6 +49,13 @@ export function collect(specifiers, options) {
|
|
|
49
49
|
return `${cdn}/${name}${version}/${clean}`;
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
+
// A stylesheet as a url a browser can fetch, mapped to its loader sibling: a browser cannot
|
|
53
|
+
// import a stylesheet as a module, the loader adds it as a <link>.
|
|
54
|
+
const addStylesheet = (key, pkg, dir, file) => {
|
|
55
|
+
stylesheets.add(urlFor(pkg, dir, file));
|
|
56
|
+
imports[key] = css === 'loader' ? urlFor(pkg, dir, file + '.js') : 'data:text/javascript,';
|
|
57
|
+
};
|
|
58
|
+
|
|
52
59
|
const add = (spec) => {
|
|
53
60
|
if (visited.has(spec)) return;
|
|
54
61
|
visited.add(spec);
|
|
@@ -61,10 +68,8 @@ export function collect(specifiers, options) {
|
|
|
61
68
|
if (!file) return void unresolved.add(spec);
|
|
62
69
|
|
|
63
70
|
if (spec.endsWith('.css')) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// it as a <link>, so importing a component still brings its styles.
|
|
67
|
-
imports[spec] = css === 'loader' ? urlFor(pkg, dir, file + '.js') : 'data:text/javascript,';
|
|
71
|
+
// Importing a component still brings its styles.
|
|
72
|
+
addStylesheet(spec, pkg, dir, file);
|
|
68
73
|
return;
|
|
69
74
|
}
|
|
70
75
|
|
|
@@ -78,7 +83,12 @@ export function collect(specifiers, options) {
|
|
|
78
83
|
if (seen.has(current) || !existsSync(current)) continue;
|
|
79
84
|
seen.add(current);
|
|
80
85
|
for (const nested of scanImports(current)) {
|
|
81
|
-
if (nested.startsWith('.')) {
|
|
86
|
+
if (nested.startsWith('.') && nested.endsWith('.css')) {
|
|
87
|
+
// A module's own stylesheet (`import './button.css'`). The browser resolves it to a
|
|
88
|
+
// url before it reads the map, so the url is the key.
|
|
89
|
+
const file = './' + relative(dir, normalize(join(dirname(current), nested))).split('\\').join('/');
|
|
90
|
+
addStylesheet(urlFor(pkg, dir, file), pkg, dir, file);
|
|
91
|
+
} else if (nested.startsWith('.')) {
|
|
82
92
|
const next = normalize(join(dirname(current), nested));
|
|
83
93
|
stack.push(existsSync(next) ? next : next + '.js');
|
|
84
94
|
} else if (!nested.startsWith('node:')) {
|