@parcel/utils 2.13.3 → 2.14.1
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/lib/index.js +28 -4
- package/lib/index.js.map +1 -1
- package/package.json +7 -7
- package/src/import-map.js +47 -0
- package/src/index.js +1 -0
- package/src/urlJoin.js +15 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.1",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@parcel/codeframe": "2.
|
|
37
|
-
"@parcel/diagnostic": "2.
|
|
38
|
-
"@parcel/logger": "2.
|
|
39
|
-
"@parcel/markdown-ansi": "2.
|
|
40
|
-
"@parcel/rust": "2.
|
|
36
|
+
"@parcel/codeframe": "2.14.1",
|
|
37
|
+
"@parcel/diagnostic": "2.14.1",
|
|
38
|
+
"@parcel/logger": "2.14.1",
|
|
39
|
+
"@parcel/markdown-ansi": "2.14.1",
|
|
40
|
+
"@parcel/rust": "2.14.1",
|
|
41
41
|
"@parcel/source-map": "^2.1.1",
|
|
42
42
|
"chalk": "^4.1.2",
|
|
43
43
|
"nullthrows": "^1.1.1"
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"./src/openInBrowser.js": false,
|
|
67
67
|
"@parcel/markdown-ansi": false
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "86bddb4031136f4b1b76e1a9a4c8a53ff4280b42"
|
|
70
70
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type {BundleGraph, NamedBundle} from '@parcel/types';
|
|
3
|
+
import {normalizeSeparators} from './path';
|
|
4
|
+
|
|
5
|
+
export function getImportMap(
|
|
6
|
+
bundleGraph: BundleGraph<NamedBundle>,
|
|
7
|
+
entryBundle: NamedBundle,
|
|
8
|
+
): {[string]: string} {
|
|
9
|
+
let mappings = {};
|
|
10
|
+
for (let childBundle of bundleGraph.getChildBundles(entryBundle)) {
|
|
11
|
+
bundleGraph.traverseBundles((bundle, _, actions) => {
|
|
12
|
+
if (bundle.bundleBehavior === 'inline') {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
mappings[bundle.publicId] = normalizeSeparators(bundle.name);
|
|
17
|
+
|
|
18
|
+
if (bundle !== entryBundle && isNewContext(bundle, bundleGraph)) {
|
|
19
|
+
for (let referenced of bundleGraph.getReferencedBundles(bundle)) {
|
|
20
|
+
mappings[referenced.publicId] = normalizeSeparators(referenced.name);
|
|
21
|
+
}
|
|
22
|
+
// New contexts have their own manifests, so there's no need to continue.
|
|
23
|
+
actions.skipChildren();
|
|
24
|
+
}
|
|
25
|
+
}, childBundle);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return mappings;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isNewContext(
|
|
32
|
+
bundle: NamedBundle,
|
|
33
|
+
bundleGraph: BundleGraph<NamedBundle>,
|
|
34
|
+
): boolean {
|
|
35
|
+
let parents = bundleGraph.getParentBundles(bundle);
|
|
36
|
+
let isInEntryBundleGroup = bundleGraph
|
|
37
|
+
.getBundleGroupsContainingBundle(bundle)
|
|
38
|
+
.some(g => bundleGraph.isEntryBundleGroup(g));
|
|
39
|
+
return (
|
|
40
|
+
isInEntryBundleGroup ||
|
|
41
|
+
parents.length === 0 ||
|
|
42
|
+
parents.some(
|
|
43
|
+
parent =>
|
|
44
|
+
parent.env.context !== bundle.env.context || parent.type !== 'js',
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
}
|
package/src/index.js
CHANGED
package/src/urlJoin.js
CHANGED
|
@@ -7,7 +7,11 @@ import path from 'path';
|
|
|
7
7
|
* Joins a path onto a URL, and normalizes Windows paths
|
|
8
8
|
* e.g. from \path\to\res.js to /path/to/res.js.
|
|
9
9
|
*/
|
|
10
|
-
export default function urlJoin(
|
|
10
|
+
export default function urlJoin(
|
|
11
|
+
publicURL: string,
|
|
12
|
+
assetPath: string,
|
|
13
|
+
leadingDotSlash: boolean = false,
|
|
14
|
+
): string {
|
|
11
15
|
const url = URL.parse(publicURL, false, true);
|
|
12
16
|
// Leading / ensures that paths with colons are not parsed as a protocol.
|
|
13
17
|
let p = assetPath.startsWith('/') ? assetPath : '/' + assetPath;
|
|
@@ -15,5 +19,14 @@ export default function urlJoin(publicURL: string, assetPath: string): string {
|
|
|
15
19
|
url.pathname = path.posix.join(url.pathname, assetUrl.pathname);
|
|
16
20
|
url.search = assetUrl.search;
|
|
17
21
|
url.hash = assetUrl.hash;
|
|
18
|
-
|
|
22
|
+
let result = URL.format(url);
|
|
23
|
+
if (
|
|
24
|
+
url.host == null &&
|
|
25
|
+
result[0] !== '/' &&
|
|
26
|
+
result[0] !== '.' &&
|
|
27
|
+
leadingDotSlash
|
|
28
|
+
) {
|
|
29
|
+
result = './' + result;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
19
32
|
}
|