@temir.ra/create-ts-lib 0.11.1 → 0.12.0-pre.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Version 0
2
2
 
3
+ ## 0.12.0-pre.1
4
+
5
+ 1. Refactored `scripts/build-bundle.ts` to use an import map plugin instead of a CDN rewrite plugin.
6
+
3
7
  ## 0.11.1
4
8
 
5
9
  1. Updated from `template@0.4.1` template.
package/README.md CHANGED
@@ -8,7 +8,7 @@ A template for TypeScript libraries distributed via npm-compatible registries. P
8
8
  2. [Documentation](#documentation)
9
9
  1. [`package.json`](#packagejson)
10
10
  2. [Script `scripts/build-bundle.ts`](#script-scriptsbuild-bundlets)
11
- 1. [CDN Map `scripts/cdn-rewrite-map.json`](#cdn-map-scriptscdn-rewrite-mapjson)
11
+ 1. [Import Map `scripts/import-map.json`](#import-map-scriptsimport-mapjson)
12
12
  3. [`tsconfig.build.json`](#tsconfigbuildjson)
13
13
  4. [Asset Resolution](#asset-resolution)
14
14
  1. [Externalized - loaded from CDN or `node_modules/`](#externalized---loaded-from-cdn-or-node_modules)
@@ -75,7 +75,7 @@ The following fields are specific to this template:
75
75
  "files": [
76
76
  "scripts/buildinfo.ts",
77
77
  "scripts/build-bundle.ts",
78
- "scripts/cdn-rewrite-map.json",
78
+ "scripts/import-map.json",
79
79
  "CHANGELOG.md",
80
80
  "buildinfo.txt",
81
81
  "dist/",
@@ -157,17 +157,22 @@ The following fields are specific to this template:
157
157
 
158
158
  Bundles the library to ESM and IIFE formats using `esbuild`. Entry points are resolved from the `entrypoint` condition in the `exports` field of `package.json`. Note, the `entrypoint` condition is a custom, non-standard export condition used solely for build tooling.
159
159
 
160
- Import specifiers can be rewritten to CDN URLs via `scripts/cdn-rewrite-map.json`.
160
+ Import specifiers can be mapped to CDN URLs or marked as external via `scripts/import-map.json`.
161
161
 
162
- ### CDN Map `scripts/cdn-rewrite-map.json`
162
+ ### Import Map `scripts/import-map.json`
163
163
 
164
- Maps import specifiers to CDN URLs. During bundling, matching specifiers in source files are rewritten to their CDN equivalents.
164
+ Maps import specifiers to CDN URLs or marks them as external without rewriting. During bundling, matching specifiers in source files are resolved according to the map.
165
+
166
+ - **Truthy value**: rewrites the import to the given URL and marks it external.
167
+ - **Falsy value**: marks the import external without rewriting; the original specifier is preserved.
165
168
 
166
169
  `<VERSION>` in a URL is replaced with the version of the matching package from `package.json`.
167
170
 
168
171
  ```json
169
172
  {
170
- "import-specifier": "https://cdn.jsdelivr.net/npm/package-name@<VERSION>/dist/index.bundle.js"
173
+ "rewrite-package": "https://cdn.jsdelivr.net/npm/rewrite-package@<VERSION>/dist/index.js",
174
+ "rewrite-package-without-version": "https://cdn.jsdelivr.net/npm/rewrite-package/dist/index.js",
175
+ "external-only-package": null
171
176
  }
172
177
  ```
173
178
 
package/buildinfo.txt CHANGED
@@ -1 +1 @@
1
- 0.11.1+18c476f
1
+ 0.12.0-pre.1+78f65d1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temir.ra/create-ts-lib",
3
- "version": "0.11.1",
3
+ "version": "0.12.0-pre.1",
4
4
  "description": "A template for a distributable TypeScript library package.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -16,7 +16,7 @@
16
16
  "files": [
17
17
  "scripts/buildinfo.ts",
18
18
  "scripts/build-bundle.ts",
19
- "scripts/cdn-rewrite-map.json",
19
+ "scripts/import-map.json",
20
20
  "CHANGELOG.md",
21
21
  "buildinfo.txt",
22
22
  "dist/",
@@ -11,7 +11,7 @@ import {
11
11
  type BuildResult
12
12
  } from 'esbuild';
13
13
 
14
- import CDN_REWRITE_MAP from './cdn-rewrite-map.json';
14
+ import IMPORT_MAP from './import-map.json';
15
15
 
16
16
 
17
17
  interface ExportConditions {
@@ -122,20 +122,20 @@ const esbuildLog: EsbuildPlugin = {
122
122
  });
123
123
  }
124
124
  }
125
- const cdnRewrite: EsbuildPlugin = {
126
- name: 'cdn-rewrite',
125
+ const importMap: EsbuildPlugin = {
126
+ name: 'import-map',
127
127
  setup(build: PluginBuild) {
128
128
 
129
- for (const [importSpecifier, urlTemplate] of Object.entries(CDN_REWRITE_MAP) as [string, string][]) {
129
+ for (const [importSpecifier, urlTemplate] of Object.entries(IMPORT_MAP) as [string, string | null][]) {
130
130
 
131
- const url = resolveVersionInCdnUrl(importSpecifier, urlTemplate);
132
- console.log(`[cdn-rewrite plugin] '${importSpecifier}' → '${url}'`);
131
+ const url = urlTemplate ? resolveVersionInCdnUrl(importSpecifier, urlTemplate) : null;
132
+ console.log(`[import-map plugin] '${importSpecifier}' → ${url ? `'${url}'` : 'external (no rewrite)'}`);
133
133
 
134
134
  const escapedSpecifier = importSpecifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
135
135
  build.onResolve(
136
136
  { filter: new RegExp(`^${escapedSpecifier}$`) },
137
137
  (args: OnResolveArgs): OnResolveResult | undefined => {
138
- return { path: url, external: true };
138
+ return { path: url ?? args.path, external: true };
139
139
  }
140
140
  );
141
141
 
@@ -157,7 +157,7 @@ const buildOptions: BuildOptions = {
157
157
  bundle: true,
158
158
  minify: true,
159
159
  sourcemap: 'external',
160
- plugins: [esbuildLog, cdnRewrite],
160
+ plugins: [esbuildLog, importMap],
161
161
 
162
162
  };
163
163
 
@@ -0,0 +1 @@
1
+ {}
@@ -1 +0,0 @@
1
- {}