@temir.ra/create-workspace 0.4.8 → 0.5.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/CHANGELOG.md +8 -0
- package/README.md +13 -16
- package/buildinfo.txt +1 -1
- package/dist/cli.bundle.js +1 -3
- package/dist/cli.bundle.js.map +5 -9
- package/package.json +4 -3
- package/scripts/build-bundle.ts +86 -58
- package/template/package.json +1 -1
- package/template/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -39,25 +39,22 @@ Templates in this family:
|
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
41
|
# placeholder:
|
|
42
|
-
# <TEMPLATE_PACKAGE: @temir.ra/create-workspace
|
|
43
|
-
# <TEMPLATE_NAME: @temir.ra/workspace
|
|
44
42
|
# <NEW_PACKAGE: <NEW_PACKAGE>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
# <TEMPLATE_PACKAGE_NAME: @temir.ra/create-workspace
|
|
44
|
+
# <TEMPLATE_NAME: @temir.ra/workspace
|
|
45
|
+
|
|
46
|
+
mkdir -p <NEW_PACKAGE>
|
|
47
|
+
cd <NEW_PACKAGE>
|
|
49
48
|
|
|
50
|
-
#
|
|
49
|
+
# print the latest version
|
|
51
50
|
bun info "@temir.ra/create-workspace" version
|
|
52
|
-
bun create --no-install --no-git "@temir.ra/workspace<@_VERSION>" <NEW_PACKAGE>
|
|
53
51
|
|
|
54
|
-
#
|
|
55
|
-
# clear the cache to pick up the latest version
|
|
56
|
-
bun
|
|
57
|
-
|
|
52
|
+
# create/update a package from the template in the current directory
|
|
53
|
+
# clear the package manager cache to pick up the latest version when not pinning a specific version
|
|
54
|
+
bun create --no-install --no-git "@temir.ra/workspace" .
|
|
55
|
+
|
|
56
|
+
# set metadata in package.json
|
|
58
57
|
|
|
59
|
-
# templates only copy files, run install and any setup scripts manually
|
|
60
|
-
cd <NEW_PACKAGE>
|
|
61
58
|
bun install
|
|
62
59
|
```
|
|
63
60
|
|
|
@@ -104,7 +101,7 @@ See npmjs documentation on [package.json](https://docs.npmjs.com/cli/v11/configu
|
|
|
104
101
|
},
|
|
105
102
|
|
|
106
103
|
"devDependencies": {
|
|
107
|
-
"@types/
|
|
104
|
+
"@types/node": "latest",
|
|
108
105
|
"typescript": "^6.0.3"
|
|
109
106
|
}
|
|
110
107
|
|
|
@@ -168,7 +165,7 @@ See the TypeScript documentation on [tsconfig.json](https://www.typescriptlang.o
|
|
|
168
165
|
"skipLibCheck": true,
|
|
169
166
|
|
|
170
167
|
// TS6 defaults types to [] - @types/* packages must be listed explicitly
|
|
171
|
-
"types": ["
|
|
168
|
+
"types": ["node"],
|
|
172
169
|
|
|
173
170
|
// enforce consistent casing across import statements
|
|
174
171
|
"forceConsistentCasingInFileNames": true,
|
package/buildinfo.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.5.0+3d1f68d
|
package/dist/cli.bundle.js
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cpSync as a,readFileSync as g,renameSync as U,writeFileSync as d}from"fs";import{resolve as r}from"path";var n=new URL("../",import.meta.url),i=new URL("buildinfo.txt",n),u=new URL("dist/",n),l=new URL("template/",n),m=new URL("CHANGELOG.md",n),p=new URL("README.md",n);try{let t=process.argv[2];if(!t)throw Error('First argument must be the package name (e.g. "my-package" or "@my-scope/my-package").');let o=t.replace(/\\/g,"/"),e=r(process.cwd(),o);a(l,e,{recursive:!0}),a(m,r(e,"CHANGELOG-template.md")),a(i,r(e,"buildinfo-template.txt")),a(p,r(e,"README-template.md"));let c=r(e,"package.json"),s=JSON.parse(g(c,"utf-8"));s.name=o,d(c,JSON.stringify(s,null,2)),U(r(e,"gitignore"),r(e,".gitignore")),console.log(`Template has been successfully instantiated at '${e}' with package name '${o}'.`)}catch(t){let o=t instanceof Error?t:Error(String(t));console.error("Error:",o.message),process.exit(1)}
|
|
3
|
-
|
|
4
|
-
//# debugId=EF224A42FEFD5AB864756E2164756E21
|
|
2
|
+
import{cpSync as a,readFileSync as g,renameSync as U,writeFileSync as d}from"fs";import{resolve as r}from"path";var n=new URL("../",import.meta.url),i=new URL("buildinfo.txt",n),u=new URL("dist/",n),l=new URL("template/",n),m=new URL("CHANGELOG.md",n),p=new URL("README.md",n);try{let t=process.argv[2];if(!t)throw new Error('First argument must be the package name (e.g. "my-package" or "@my-scope/my-package").');let o=t.replace(/\\/g,"/"),e=r(process.cwd(),o);a(l,e,{recursive:!0}),a(m,r(e,"CHANGELOG-template.md")),a(i,r(e,"buildinfo-template.txt")),a(p,r(e,"README-template.md"));let c=r(e,"package.json"),s=JSON.parse(g(c,"utf-8"));s.name=o,d(c,JSON.stringify(s,null,2)),U(r(e,"gitignore"),r(e,".gitignore")),console.log(`Template has been successfully instantiated at '${e}' with package name '${o}'.`)}catch(t){let o=t instanceof Error?t:new Error(String(t));console.error("Error:",o.message),process.exit(1)}
|
package/dist/cli.bundle.js.map
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"mappings": ";AAEA,iBAAS,kBAAQ,gBAAc,mBAAY,WAC3C,kBAAS,aCHF,IAAM,EAAkB,IAAI,IAAI,MAAO,YAAY,GAAG,EAChD,EAAoB,IAAI,IAAI,gBAAiB,CAAU,EACvD,EAAe,IAAI,IAAI,QAAS,CAAU,EAE1C,EAAmB,IAAI,IAAI,YAAa,CAAU,EAClD,EAAoB,IAAI,IAAI,eAAgB,CAAU,EACtD,EAAiB,IAAI,IAAI,YAAa,CAAU,EDM7D,GAAI,CAEA,IAAM,EAAsB,QAAQ,KAAK,GACzC,GAAI,CAAC,EACD,MAAU,MAAM,wFAAwF,EAC5G,IAAM,EAAc,EAAoB,QAAQ,MAAO,GAAG,EAEpD,EAAkB,EAAQ,QAAQ,IAAI,EAAG,CAAW,EAE1D,EAAO,EAAa,EAAiB,CAAE,UAAW,EAAK,CAAC,EACxD,EAAO,EAAc,EAAQ,EAAiB,uBAAuB,CAAC,EACtE,EAAO,EAAc,EAAQ,EAAiB,wBAAwB,CAAC,EACvE,EAAO,EAAW,EAAQ,EAAiB,oBAAoB,CAAC,EAEhE,IAAM,EAAkB,EAAQ,EAAiB,cAAc,EACzD,EAAc,KAAK,MAAM,EAAa,EAAiB,OAAO,CAAC,EACrE,EAAY,KAAO,EACnB,EAAc,EAAiB,KAAK,UAAU,EAAa,KAAM,CAAC,CAAC,EAEnE,EAAW,EAAQ,EAAiB,WAAW,EAAG,EAAQ,EAAiB,YAAY,CAAC,EAExF,QAAQ,IAAI,mDAAmD,yBAAuC,KAAe,EAGzH,MAAO,EAAO,CACV,IAAM,EAAM,aAAiB,MAAQ,EAAY,MAAM,OAAO,CAAK,CAAC,EACpE,QAAQ,MAAM,SAAU,EAAI,OAAO,EACnC,QAAQ,KAAK,CAAC",
|
|
9
|
-
"debugId": "EF224A42FEFD5AB864756E2164756E21",
|
|
10
|
-
"names": []
|
|
11
|
-
}
|
|
3
|
+
"sources": ["../src/cli.ts", "../src/constants.ts"],
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, renameSync, writeFileSync } from 'fs';\r\nimport { resolve } from 'path';\r\nimport {\r\n templateUrl,\r\n changelogUrl,\r\n buildinfoUrl,\r\n readmeUrl\r\n} from './constants.js';\r\n\r\n\r\ntry {\r\n\r\n const packageNameArgument = process.argv[2];\r\n if (!packageNameArgument)\r\n throw new Error('First argument must be the package name (e.g. \"my-package\" or \"@my-scope/my-package\").');\r\n const packageName = packageNameArgument.replace(/\\\\/g, '/');\r\n\r\n const destinationPath = resolve(process.cwd(), packageName);\r\n\r\n cpSync(templateUrl, destinationPath, { recursive: true });\r\n cpSync(changelogUrl, resolve(destinationPath, 'CHANGELOG-template.md'));\r\n cpSync(buildinfoUrl, resolve(destinationPath, 'buildinfo-template.txt'));\r\n cpSync(readmeUrl, resolve(destinationPath, 'README-template.md'));\r\n\r\n const packageJsonPath = resolve(destinationPath, 'package.json');\r\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\r\n packageJson.name = packageName;\r\n writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));\r\n\r\n renameSync(resolve(destinationPath, 'gitignore'), resolve(destinationPath, '.gitignore'));\r\n\r\n console.log(`Template has been successfully instantiated at '${destinationPath}' with package name '${packageName}'.`);\r\n\r\n}\r\ncatch (error) {\r\n const err = error instanceof Error ? error : new Error(String(error));\r\n console.error('Error:', err.message);\r\n process.exit(1);\r\n}\r\n", "export const packageUrl: URL = new URL('../', import.meta.url);\r\nexport const buildinfoUrl: URL = new URL('buildinfo.txt', packageUrl);\r\nexport const distUrl: URL = new URL('dist/', packageUrl);\r\n\r\nexport const templateUrl: URL = new URL('template/', packageUrl);\r\nexport const changelogUrl: URL = new URL('CHANGELOG.md', packageUrl);\r\nexport const readmeUrl: URL = new URL('README.md', packageUrl);\r\n"],
|
|
5
|
+
"mappings": ";AAEA,OAAS,UAAAA,EAAQ,gBAAAC,EAAc,cAAAC,EAAY,iBAAAC,MAAqB,KAChE,OAAS,WAAAC,MAAe,OCHjB,IAAMC,EAAkB,IAAI,IAAI,MAAO,YAAY,GAAG,EAChDC,EAAoB,IAAI,IAAI,gBAAiBD,CAAU,EACvDE,EAAe,IAAI,IAAI,QAASF,CAAU,EAE1CG,EAAmB,IAAI,IAAI,YAAaH,CAAU,EAClDI,EAAoB,IAAI,IAAI,eAAgBJ,CAAU,EACtDK,EAAiB,IAAI,IAAI,YAAaL,CAAU,EDM7D,GAAI,CAEA,IAAMM,EAAsB,QAAQ,KAAK,CAAC,EAC1C,GAAI,CAACA,EACD,MAAM,IAAI,MAAM,wFAAwF,EAC5G,IAAMC,EAAcD,EAAoB,QAAQ,MAAO,GAAG,EAEpDE,EAAkBC,EAAQ,QAAQ,IAAI,EAAGF,CAAW,EAE1DG,EAAOC,EAAaH,EAAiB,CAAE,UAAW,EAAK,CAAC,EACxDE,EAAOE,EAAcH,EAAQD,EAAiB,uBAAuB,CAAC,EACtEE,EAAOG,EAAcJ,EAAQD,EAAiB,wBAAwB,CAAC,EACvEE,EAAOI,EAAWL,EAAQD,EAAiB,oBAAoB,CAAC,EAEhE,IAAMO,EAAkBN,EAAQD,EAAiB,cAAc,EACzDQ,EAAc,KAAK,MAAMC,EAAaF,EAAiB,OAAO,CAAC,EACrEC,EAAY,KAAOT,EACnBW,EAAcH,EAAiB,KAAK,UAAUC,EAAa,KAAM,CAAC,CAAC,EAEnEG,EAAWV,EAAQD,EAAiB,WAAW,EAAGC,EAAQD,EAAiB,YAAY,CAAC,EAExF,QAAQ,IAAI,mDAAmDA,CAAe,wBAAwBD,CAAW,IAAI,CAEzH,OACOa,EAAO,CACV,IAAMC,EAAMD,aAAiB,MAAQA,EAAQ,IAAI,MAAM,OAAOA,CAAK,CAAC,EACpE,QAAQ,MAAM,SAAUC,EAAI,OAAO,EACnC,QAAQ,KAAK,CAAC,CAClB",
|
|
6
|
+
"names": ["cpSync", "readFileSync", "renameSync", "writeFileSync", "resolve", "packageUrl", "buildinfoUrl", "distUrl", "templateUrl", "changelogUrl", "readmeUrl", "packageNameArgument", "packageName", "destinationPath", "resolve", "cpSync", "templateUrl", "changelogUrl", "buildinfoUrl", "readmeUrl", "packageJsonPath", "packageJson", "readFileSync", "writeFileSync", "renameSync", "error", "err"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temir.ra/create-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A template for a generic TypeScript workspace.",
|
|
5
5
|
"author": "temir.ra",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"typescript",
|
|
9
|
-
"bun",
|
|
10
9
|
"template",
|
|
11
10
|
"workspace"
|
|
12
11
|
],
|
|
@@ -39,10 +38,12 @@
|
|
|
39
38
|
"tests": "bun test",
|
|
40
39
|
"prebuild": "bun run buildinfo",
|
|
41
40
|
"build": "bun run build:cli-bundle",
|
|
42
|
-
"build:cli-bundle": "
|
|
41
|
+
"build:cli-bundle": "esbuild src/cli.ts --outdir=dist --entry-names=[dir]/[name].bundle --platform=node --format=esm --bundle --minify --sourcemap=external"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@types/bun": "latest",
|
|
45
|
+
"@types/node": "latest",
|
|
46
|
+
"esbuild": "latest",
|
|
46
47
|
"typescript": "^6.0.3"
|
|
47
48
|
}
|
|
48
49
|
}
|
package/scripts/build-bundle.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
+
import {
|
|
4
|
+
build,
|
|
5
|
+
type BuildFailure,
|
|
6
|
+
type OnResolveArgs,
|
|
7
|
+
type OnResolveResult,
|
|
8
|
+
type Plugin as EsbuildPlugin,
|
|
9
|
+
type PluginBuild,
|
|
10
|
+
type BuildOptions,
|
|
11
|
+
type BuildResult
|
|
12
|
+
} from 'esbuild';
|
|
3
13
|
|
|
4
14
|
import CDN_REWRITE_MAP from './cdn-rewrite-map.json';
|
|
5
15
|
|
|
@@ -11,17 +21,15 @@ interface ExportConditions {
|
|
|
11
21
|
browser?: string;
|
|
12
22
|
import?: string;
|
|
13
23
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[packageName: string]: string;
|
|
24
|
+
interface Dependency {
|
|
25
|
+
[key: string]: string;
|
|
17
26
|
}
|
|
18
|
-
|
|
19
27
|
interface PackageManifest {
|
|
20
28
|
version: string;
|
|
21
29
|
exports?: Record<string, ExportConditions>;
|
|
22
|
-
dependencies?:
|
|
23
|
-
devDependencies?:
|
|
24
|
-
peerDependencies?:
|
|
30
|
+
dependencies?: Dependency;
|
|
31
|
+
devDependencies?: Dependency;
|
|
32
|
+
peerDependencies?: Dependency;
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
function getManifest(packageIdentifier?: string): PackageManifest {
|
|
@@ -32,6 +40,7 @@ function getManifest(packageIdentifier?: string): PackageManifest {
|
|
|
32
40
|
;
|
|
33
41
|
|
|
34
42
|
let manifest: PackageManifest;
|
|
43
|
+
|
|
35
44
|
try {
|
|
36
45
|
manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
37
46
|
} catch {
|
|
@@ -41,24 +50,22 @@ function getManifest(packageIdentifier?: string): PackageManifest {
|
|
|
41
50
|
return manifest;
|
|
42
51
|
|
|
43
52
|
}
|
|
44
|
-
|
|
45
53
|
function getManifestEntrypoints(packageManifest: PackageManifest): string[] {
|
|
46
54
|
|
|
47
55
|
const exports = packageManifest.exports;
|
|
48
56
|
if (!exports)
|
|
49
|
-
throw new Error(`[scripts/build-bundle.ts]
|
|
57
|
+
throw new Error(`[scripts/build-bundle.ts] Failed to read entrypoints from package manifest: 'exports' field is missing.`);
|
|
50
58
|
|
|
51
59
|
const entrypoints = Object.entries(exports)
|
|
52
60
|
.map(([key, conditions]) => {
|
|
53
61
|
if (!conditions.entrypoint)
|
|
54
|
-
throw new Error(`[scripts/build-bundle.ts]
|
|
62
|
+
throw new Error(`[scripts/build-bundle.ts] Failed to read entrypoints from package manifest: 'entrypoint' condition is missing for export '${key}'.`);
|
|
55
63
|
return conditions.entrypoint;
|
|
56
64
|
});
|
|
57
65
|
|
|
58
66
|
return entrypoints;
|
|
59
67
|
|
|
60
68
|
}
|
|
61
|
-
|
|
62
69
|
function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string): string {
|
|
63
70
|
|
|
64
71
|
let version: string | undefined;
|
|
@@ -72,12 +79,12 @@ function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string
|
|
|
72
79
|
|
|
73
80
|
version = dependencies[packageIdentifier];
|
|
74
81
|
if (!version)
|
|
75
|
-
throw new Error(`[scripts/build-bundle.ts]
|
|
82
|
+
throw new Error(`[scripts/build-bundle.ts] Failed to read version for package '${packageIdentifier}': package is not listed in dependencies.`);
|
|
76
83
|
|
|
77
84
|
}
|
|
78
85
|
else {
|
|
79
86
|
if (!manifest.version)
|
|
80
|
-
throw new Error('[scripts/build-bundle.ts]
|
|
87
|
+
throw new Error('[scripts/build-bundle.ts] Failed to read package version from manifest: version field is missing.');
|
|
81
88
|
version = manifest.version;
|
|
82
89
|
}
|
|
83
90
|
|
|
@@ -85,27 +92,54 @@ function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string
|
|
|
85
92
|
|
|
86
93
|
}
|
|
87
94
|
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
function resolveVersionInCdnUrl(importSpecifier: string, cdnUrl: string): string {
|
|
96
|
+
if (cdnUrl.includes('<VERSION>')) {
|
|
97
|
+
const manifest = getManifest();
|
|
98
|
+
const version = getPackageVersion(manifest, importSpecifier);
|
|
99
|
+
let resolvedVersion = version;
|
|
100
|
+
if (resolvedVersion.startsWith('workspace:')) resolvedVersion = resolvedVersion.replace(/^workspace:/, '');
|
|
101
|
+
if (resolvedVersion.startsWith('^') || resolvedVersion.startsWith('~')) resolvedVersion = resolvedVersion.substring(1);
|
|
102
|
+
if (resolvedVersion.length === 0)
|
|
103
|
+
throw new Error(`[scripts/build-bundle.ts] Failed to resolve version for package '${importSpecifier}': resolved version is empty.`);
|
|
104
|
+
return cdnUrl.replace('<VERSION>', resolvedVersion);
|
|
105
|
+
}
|
|
106
|
+
return cdnUrl;
|
|
92
107
|
}
|
|
93
108
|
|
|
94
|
-
const
|
|
109
|
+
const esbuildLog: EsbuildPlugin = {
|
|
110
|
+
name: 'esbuild-log',
|
|
111
|
+
setup(build: PluginBuild) {
|
|
112
|
+
const format = build.initialOptions.format || 'unknown';
|
|
113
|
+
build.onStart(() => {
|
|
114
|
+
console.log(`[esbuild-log plugin] ${format} build started...`);
|
|
115
|
+
});
|
|
116
|
+
build.onEnd((result: BuildResult<BuildOptions>) => {
|
|
117
|
+
if (result.errors.length > 0) {
|
|
118
|
+
console.error(`[esbuild-log plugin] ${format} build failed.`);
|
|
119
|
+
} else {
|
|
120
|
+
console.log(`[esbuild-log plugin] ${format} build finished.`);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const cdnRewrite: EsbuildPlugin = {
|
|
95
126
|
name: 'cdn-rewrite',
|
|
96
|
-
setup(build:
|
|
127
|
+
setup(build: PluginBuild) {
|
|
97
128
|
|
|
98
|
-
const resolved = new Map<string, string>();
|
|
99
129
|
for (const [importSpecifier, urlTemplate] of Object.entries(CDN_REWRITE_MAP) as [string, string][]) {
|
|
100
|
-
const url = resolveCdnUrl(importSpecifier, urlTemplate);
|
|
101
|
-
resolved.set(importSpecifier, url);
|
|
102
|
-
console.log(`[cdn-rewrite] '${importSpecifier}' → '${url}'`);
|
|
103
|
-
}
|
|
104
130
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
131
|
+
const url = resolveVersionInCdnUrl(importSpecifier, urlTemplate);
|
|
132
|
+
console.log(`[cdn-rewrite plugin] '${importSpecifier}' → '${url}'`);
|
|
133
|
+
|
|
134
|
+
const escapedSpecifier = importSpecifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
135
|
+
build.onResolve(
|
|
136
|
+
{ filter: new RegExp(`^${escapedSpecifier}$`) },
|
|
137
|
+
(args: OnResolveArgs): OnResolveResult | undefined => {
|
|
138
|
+
return { path: url, external: true };
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
}
|
|
109
143
|
|
|
110
144
|
},
|
|
111
145
|
};
|
|
@@ -114,50 +148,44 @@ const cdnRewritePlugin = {
|
|
|
114
148
|
const entrypoints = getManifestEntrypoints(getManifest());
|
|
115
149
|
console.log('[scripts/build-bundle.ts] Entrypoints:', entrypoints);
|
|
116
150
|
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
buildResult = await Bun.build({
|
|
123
|
-
entrypoints,
|
|
124
|
-
outdir: 'dist',
|
|
125
|
-
naming: '[dir]/[name].bundle.[ext]',
|
|
126
|
-
target: 'browser',
|
|
151
|
+
const buildOptions: BuildOptions = {
|
|
152
|
+
entryPoints: entrypoints,
|
|
153
|
+
outdir: 'dist/',
|
|
154
|
+
entryNames: '[dir]/[name].bundle',
|
|
155
|
+
platform: 'browser',
|
|
127
156
|
format: 'esm',
|
|
157
|
+
bundle: true,
|
|
128
158
|
minify: true,
|
|
129
159
|
sourcemap: 'external',
|
|
130
|
-
plugins: [
|
|
131
|
-
});
|
|
160
|
+
plugins: [esbuildLog, cdnRewrite],
|
|
132
161
|
|
|
133
|
-
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
await build(buildOptions);
|
|
166
|
+
} catch (error) {
|
|
134
167
|
console.error('[scripts/build-bundle.ts] Build failed:');
|
|
135
|
-
for (const message of
|
|
168
|
+
for (const message of (error as BuildFailure).errors) {
|
|
136
169
|
console.error(message);
|
|
137
170
|
}
|
|
138
171
|
process.exit(1);
|
|
139
172
|
}
|
|
140
|
-
console.log('[scripts/build-bundle.ts] ESM bundle build completed successfully.');
|
|
141
173
|
|
|
174
|
+
const omitIife = process.argv.includes('--omit-iife');
|
|
142
175
|
if (!omitIife) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
plugins: [cdnRewritePlugin],
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
if (!buildResult.success) {
|
|
176
|
+
try {
|
|
177
|
+
await build({
|
|
178
|
+
...buildOptions,
|
|
179
|
+
entryNames: '[dir]/[name].iife.bundle',
|
|
180
|
+
format: 'iife',
|
|
181
|
+
banner: { js: 'var __importMetaUrl = document.currentScript && document.currentScript.src || \'\';' },
|
|
182
|
+
define: { 'import.meta.url': '__importMetaUrl' },
|
|
183
|
+
});
|
|
184
|
+
} catch (error) {
|
|
156
185
|
console.error('[scripts/build-bundle.ts] Build failed:');
|
|
157
|
-
for (const message of
|
|
186
|
+
for (const message of (error as BuildFailure).errors) {
|
|
158
187
|
console.error(message);
|
|
159
188
|
}
|
|
160
189
|
process.exit(1);
|
|
161
190
|
}
|
|
162
|
-
console.log('[scripts/build-bundle.ts] IIFE bundle build completed successfully.');
|
|
163
191
|
}
|
package/template/package.json
CHANGED