@temir.ra/create-workspace 0.4.8 → 0.4.9
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/CHANGELOG.md +4 -0
- package/buildinfo.txt +1 -1
- package/package.json +1 -1
- package/scripts/build-bundle.ts +22 -11
package/CHANGELOG.md
CHANGED
package/buildinfo.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.4.
|
|
1
|
+
0.4.9+59c34b7
|
package/package.json
CHANGED
package/scripts/build-bundle.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface ExportConditions {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
interface DependencyMap {
|
|
16
|
-
[
|
|
16
|
+
[key: string]: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
interface PackageManifest {
|
|
@@ -86,26 +86,37 @@ function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
function resolveCdnUrl(importSpecifier: string, urlTemplate: string): string {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
if (urlTemplate.includes('<VERSION>')) {
|
|
90
|
+
const manifest = getManifest();
|
|
91
|
+
const version = getPackageVersion(manifest, importSpecifier);
|
|
92
|
+
let resolvedVersion = version;
|
|
93
|
+
if (resolvedVersion.startsWith('workspace:')) resolvedVersion = resolvedVersion.replace(/^workspace:/, '');
|
|
94
|
+
if (resolvedVersion.startsWith('^') || resolvedVersion.startsWith('~')) resolvedVersion = resolvedVersion.substring(1);
|
|
95
|
+
if (resolvedVersion.length !== 0)
|
|
96
|
+
return urlTemplate.replace('<VERSION>', resolvedVersion);
|
|
97
|
+
}
|
|
98
|
+
return urlTemplate;
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
const cdnRewritePlugin = {
|
|
95
102
|
name: 'cdn-rewrite',
|
|
96
103
|
setup(build: any) {
|
|
97
104
|
|
|
98
|
-
const resolved
|
|
105
|
+
const resolved: Record<string, string> = {};
|
|
99
106
|
for (const [importSpecifier, urlTemplate] of Object.entries(CDN_REWRITE_MAP) as [string, string][]) {
|
|
107
|
+
|
|
100
108
|
const url = resolveCdnUrl(importSpecifier, urlTemplate);
|
|
101
|
-
resolved
|
|
109
|
+
resolved[importSpecifier] = url;
|
|
110
|
+
|
|
111
|
+
const escapedSpecifier = importSpecifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
102
112
|
console.log(`[cdn-rewrite] '${importSpecifier}' → '${url}'`);
|
|
103
|
-
}
|
|
104
113
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
build.onResolve({ filter: new RegExp(`^${escapedSpecifier}$`) }, (args: any) => {
|
|
115
|
+
const url = resolved[args.path];
|
|
116
|
+
if (url) return { path: url, external: true };
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
}
|
|
109
120
|
|
|
110
121
|
},
|
|
111
122
|
};
|