@temir.ra/create-workspace 0.4.7 → 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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Version 0
2
2
 
3
+ ## 0.4.9
4
+
5
+ 1. Synced with `ts-lib@0.8.4` template.
6
+
7
+ ## 0.4.8
8
+
9
+ 1. Synced with `template` template.
10
+
3
11
  ## 0.4.7
4
12
 
5
13
  1. Updated from `template@0.1.9` template.
package/buildinfo.txt CHANGED
@@ -1 +1 @@
1
- 0.4.7+9e366a6
1
+ 0.4.9+59c34b7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temir.ra/create-workspace",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "A template for a generic TypeScript workspace.",
5
5
  "author": "temir.ra",
6
6
  "license": "MIT",
@@ -13,7 +13,7 @@ interface ExportConditions {
13
13
  }
14
14
 
15
15
  interface DependencyMap {
16
- [packageName: string]: string;
16
+ [key: string]: string;
17
17
  }
18
18
 
19
19
  interface PackageManifest {
@@ -28,16 +28,14 @@ function getManifest(packageIdentifier?: string): PackageManifest {
28
28
 
29
29
  const manifestPath = packageIdentifier
30
30
  ? join('node_modules', packageIdentifier, 'package.json')
31
- : 'package.json';
31
+ : 'package.json'
32
+ ;
32
33
 
33
34
  let manifest: PackageManifest;
34
35
  try {
35
36
  manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
36
37
  } catch {
37
- if (packageIdentifier)
38
- throw new Error(`[scripts/build-bundle.ts] Could not read manifest for '${packageIdentifier}' at '${manifestPath}'.`);
39
- else
40
- throw new Error(`[scripts/build-bundle.ts] Could not read package manifest at '${manifestPath}'.`);
38
+ throw new Error(`[scripts/build-bundle.ts] Failed to read package manifest at '${manifestPath}'.`);
41
39
  }
42
40
 
43
41
  return manifest;
@@ -88,26 +86,37 @@ function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string
88
86
  }
89
87
 
90
88
  function resolveCdnUrl(importSpecifier: string, urlTemplate: string): string {
91
- const manifest = getManifest();
92
- const version = getPackageVersion(manifest, importSpecifier);
93
- return urlTemplate.replace('<VERSION>', version);
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;
94
99
  }
95
100
 
96
101
  const cdnRewritePlugin = {
97
102
  name: 'cdn-rewrite',
98
103
  setup(build: any) {
99
104
 
100
- const resolved = new Map<string, string>();
105
+ const resolved: Record<string, string> = {};
101
106
  for (const [importSpecifier, urlTemplate] of Object.entries(CDN_REWRITE_MAP) as [string, string][]) {
107
+
102
108
  const url = resolveCdnUrl(importSpecifier, urlTemplate);
103
- resolved.set(importSpecifier, url);
109
+ resolved[importSpecifier] = url;
110
+
111
+ const escapedSpecifier = importSpecifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
104
112
  console.log(`[cdn-rewrite] '${importSpecifier}' → '${url}'`);
105
- }
106
113
 
107
- build.onResolve({ filter: /\*/ }, (args: any) => {
108
- const url = resolved.get(args.path);
109
- if (url) return { path: url, external: true };
110
- });
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
+ }
111
120
 
112
121
  },
113
122
  };
@@ -116,6 +125,8 @@ const cdnRewritePlugin = {
116
125
  const entrypoints = getManifestEntrypoints(getManifest());
117
126
  console.log('[scripts/build-bundle.ts] Entrypoints:', entrypoints);
118
127
 
128
+ const omitIife = process.argv.includes('--omit-iife');
129
+
119
130
  let buildResult;
120
131
 
121
132
  console.log('[scripts/build-bundle.ts] Starting ESM bundle build...');
@@ -139,23 +150,25 @@ if (!buildResult.success) {
139
150
  }
140
151
  console.log('[scripts/build-bundle.ts] ESM bundle build completed successfully.');
141
152
 
142
- console.log('[scripts/build-bundle.ts] Starting IIFE bundle build...');
143
- buildResult = await Bun.build({
144
- entrypoints,
145
- outdir: 'dist',
146
- naming: '[dir]/[name].iife.[ext]',
147
- target: 'browser',
148
- format: 'iife',
149
- minify: true,
150
- sourcemap: 'external',
151
- plugins: [cdnRewritePlugin],
152
- });
153
-
154
- if (!buildResult.success) {
155
- console.error('[scripts/build-bundle.ts] Build failed:');
156
- for (const message of buildResult.logs) {
157
- console.error(message);
153
+ if (!omitIife) {
154
+ console.log('[scripts/build-bundle.ts] Starting IIFE bundle build...');
155
+ buildResult = await Bun.build({
156
+ entrypoints,
157
+ outdir: 'dist',
158
+ naming: '[dir]/[name].iife.[ext]',
159
+ target: 'browser',
160
+ format: 'iife',
161
+ minify: true,
162
+ sourcemap: 'external',
163
+ plugins: [cdnRewritePlugin],
164
+ });
165
+
166
+ if (!buildResult.success) {
167
+ console.error('[scripts/build-bundle.ts] Build failed:');
168
+ for (const message of buildResult.logs) {
169
+ console.error(message);
170
+ }
171
+ process.exit(1);
158
172
  }
159
- process.exit(1);
173
+ console.log('[scripts/build-bundle.ts] IIFE bundle build completed successfully.');
160
174
  }
161
- console.log('[scripts/build-bundle.ts] IIFE bundle build completed successfully.');