@temir.ra/create-ts-lib 0.6.3 → 0.7.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.
@@ -14,31 +14,25 @@
14
14
 
15
15
  # Quick Start
16
16
 
17
- ```bash
18
- # remove dist/ and tsconfig.tsbuildinfo and tsconfig.build.tsbuildinfo
19
- bun run clean
17
+ *<QUICK START INSTRUCTIONS>*
20
18
 
21
- # remove dist/ only
22
- bun run clean:dist
19
+ # Documentation
23
20
 
24
- # remove tsconfig.tsbuildinfo and tsconfig.build.tsbuildinfo only
25
- bun run clean:tsbuildinfo
21
+ *<DOCUMENTATION>*
26
22
 
27
- # compile + bundle
28
- bun run build
23
+ # DevOps
24
+
25
+ ```bash
26
+ bun install
29
27
 
30
- # run tests
28
+ bun run clean
29
+ bun run build
31
30
  bun run tests
32
31
 
33
- # run src/dev.ts in watch mode
34
32
  bun run dev
35
- ```
36
-
37
- # Documentation
38
33
 
39
- *<DOCUMENTATION>*
40
-
41
- # DevOps
34
+ # see publish section for publish instructions
35
+ ```
42
36
 
43
37
  ## Change Management
44
38
 
@@ -47,7 +41,7 @@ bun run dev
47
41
  3. Bump the version in [`package.json`](package.json).
48
42
  4. Add an entry for the new version in [`CHANGELOG.md`](CHANGELOG.md).
49
43
  5. Pull request the branch.
50
- 6. After merge, run `bun run build` - ensures artifacts are current before publish.
44
+ 6. Ensure package artifacts are current.
51
45
  7. Publish.
52
46
 
53
47
  ## Publish
@@ -0,0 +1 @@
1
+ 0.4.1+f472194
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -1,7 +1,7 @@
1
- dist
2
1
  node_modules
3
2
  buildinfo.txt
4
- *.tsbuildinfo
5
3
  buildinfo-template.txt
6
4
  CHANGELOG-template.md
7
5
  README-template.md
6
+ *.tsbuildinfo
7
+ dist
@@ -11,6 +11,7 @@
11
11
  "type": "git",
12
12
  "url": ""
13
13
  },
14
+ "private": false,
14
15
  "type": "module",
15
16
  "exports": {
16
17
  ".": {
@@ -24,21 +25,24 @@
24
25
  "#src/*.js": "./src/*.ts"
25
26
  },
26
27
  "files": [
27
- "dist",
28
+ "scripts/buildinfo.ts",
29
+ "scripts/build-bundle.ts",
30
+ "scripts/cdn-rewrite-map.json",
28
31
  "CHANGELOG.md",
29
- "buildinfo.txt"
32
+ "buildinfo.txt",
33
+ "dist"
30
34
  ],
31
35
  "scripts": {
36
+ "reinstall": "rm -rf node_modules && rm -f bun.lock && bun pm cache rm && bun install && bunx tsc --version",
37
+ "typecheck": "tsc --noEmit",
38
+ "buildinfo": "bun run scripts/buildinfo.ts",
32
39
  "clean:dist": "rm -rf dist/",
33
- "clean:tsbuildinfo": "rm -f tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
40
+ "clean:tsbuildinfo": "rm -f *.tsbuildinfo || true",
34
41
  "clean": "bun run clean:dist && bun run clean:tsbuildinfo",
35
- "prebuild": "bun run scripts/buildinfo.ts",
36
42
  "tests": "bun test",
37
- "build": "bun run build:lib && bun run build:lib-bundle",
38
- "build:lib": "tsc --project tsconfig.build.json",
39
- "build:lib-bundle": "bun run scripts/build-lib-bundle.ts",
40
- "typecheck": "tsc --noEmit",
41
- "dev": "bun run --watch src/dev.ts"
43
+ "prebuild": "bun run buildinfo",
44
+ "build": "bun run build:bundle",
45
+ "build:bundle": "bun run scripts/build-bundle.ts"
42
46
  },
43
47
  "devDependencies": {
44
48
  "@types/bun": "latest",
@@ -0,0 +1,161 @@
1
+ import { readFileSync } from 'fs';
2
+ import { join } from 'path';
3
+
4
+ import CDN_REWRITE_MAP from './cdn-rewrite-map.json';
5
+
6
+
7
+ interface ExportConditions {
8
+ [key: string]: string | undefined;
9
+ entrypoint?: string;
10
+ types?: string;
11
+ browser?: string;
12
+ import?: string;
13
+ }
14
+
15
+ interface DependencyMap {
16
+ [packageName: string]: string;
17
+ }
18
+
19
+ interface PackageManifest {
20
+ version: string;
21
+ exports?: Record<string, ExportConditions>;
22
+ dependencies?: DependencyMap;
23
+ devDependencies?: DependencyMap;
24
+ peerDependencies?: DependencyMap;
25
+ }
26
+
27
+ function getManifest(packageIdentifier?: string): PackageManifest {
28
+
29
+ const manifestPath = packageIdentifier
30
+ ? join('node_modules', packageIdentifier, 'package.json')
31
+ : 'package.json';
32
+
33
+ let manifest: PackageManifest;
34
+ try {
35
+ manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
36
+ } 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}'.`);
41
+ }
42
+
43
+ return manifest;
44
+
45
+ }
46
+
47
+ function getManifestEntrypoints(packageManifest: PackageManifest): string[] {
48
+
49
+ const exports = packageManifest.exports;
50
+ if (!exports)
51
+ throw new Error(`[scripts/build-bundle.ts] No 'exports' field found in the given package manifest.`);
52
+
53
+ const entrypoints = Object.entries(exports)
54
+ .map(([key, conditions]) => {
55
+ if (!conditions.entrypoint)
56
+ throw new Error(`[scripts/build-bundle.ts] Export '${key}' does not have an 'entrypoint' condition.`);
57
+ return conditions.entrypoint;
58
+ });
59
+
60
+ return entrypoints;
61
+
62
+ }
63
+
64
+ function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string): string {
65
+
66
+ let version: string | undefined;
67
+ if (packageIdentifier) {
68
+
69
+ const dependencies = {
70
+ ...manifest.dependencies,
71
+ ...manifest.devDependencies,
72
+ ...manifest.peerDependencies,
73
+ };
74
+
75
+ version = dependencies[packageIdentifier];
76
+ if (!version)
77
+ throw new Error(`[scripts/build-bundle.ts] Package '${packageIdentifier}' is not listed in dependencies.`);
78
+
79
+ }
80
+ else {
81
+ if (!manifest.version)
82
+ throw new Error('[scripts/build-bundle.ts] Package manifest does not contain a version field.');
83
+ version = manifest.version;
84
+ }
85
+
86
+ return version;
87
+
88
+ }
89
+
90
+ function resolveCdnUrl(importSpecifier: string, urlTemplate: string): string {
91
+ const manifest = getManifest();
92
+ const version = getPackageVersion(manifest, importSpecifier);
93
+ return urlTemplate.replace('<VERSION>', version);
94
+ }
95
+
96
+ const cdnRewritePlugin = {
97
+ name: 'cdn-rewrite',
98
+ setup(build: any) {
99
+
100
+ const resolved = new Map<string, string>();
101
+ for (const [importSpecifier, urlTemplate] of Object.entries(CDN_REWRITE_MAP) as [string, string][]) {
102
+ const url = resolveCdnUrl(importSpecifier, urlTemplate);
103
+ resolved.set(importSpecifier, url);
104
+ console.log(`[cdn-rewrite] '${importSpecifier}' → '${url}'`);
105
+ }
106
+
107
+ build.onResolve({ filter: /\*/ }, (args: any) => {
108
+ const url = resolved.get(args.path);
109
+ if (url) return { path: url, external: true };
110
+ });
111
+
112
+ },
113
+ };
114
+
115
+
116
+ const entrypoints = getManifestEntrypoints(getManifest());
117
+ console.log('[scripts/build-bundle.ts] Entrypoints:', entrypoints);
118
+
119
+ let buildResult;
120
+
121
+ console.log('[scripts/build-bundle.ts] Starting ESM bundle build...');
122
+ buildResult = await Bun.build({
123
+ entrypoints,
124
+ outdir: 'dist',
125
+ naming: '[dir]/[name].bundle.[ext]',
126
+ target: 'browser',
127
+ format: 'esm',
128
+ minify: true,
129
+ sourcemap: 'external',
130
+ plugins: [cdnRewritePlugin],
131
+ });
132
+
133
+ if (!buildResult.success) {
134
+ console.error('[scripts/build-bundle.ts] Build failed:');
135
+ for (const message of buildResult.logs) {
136
+ console.error(message);
137
+ }
138
+ process.exit(1);
139
+ }
140
+ console.log('[scripts/build-bundle.ts] ESM bundle build completed successfully.');
141
+
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);
158
+ }
159
+ process.exit(1);
160
+ }
161
+ console.log('[scripts/build-bundle.ts] IIFE bundle build completed successfully.');
@@ -7,7 +7,7 @@ const packageUrl = new URL('../', import.meta.url);
7
7
  console.log(`'packagePath':`, fileURLToPath(packageUrl));
8
8
 
9
9
 
10
- // dev code
10
+ // dev scratchpad
11
11
 
12
12
 
13
13
  console.log(`${(performance.now() - start).toFixed(3)}ms`);
@@ -1,39 +1,38 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "lib": [
6
- "ESNext",
7
- "DOM"
8
- ],
9
- "moduleResolution": "bundler",
10
- "strict": true,
11
- "verbatimModuleSyntax": true,
12
- "noUncheckedIndexedAccess": true,
13
- "exactOptionalPropertyTypes": true,
14
- "noImplicitOverride": true,
15
- "isolatedDeclarations": true,
16
- "esModuleInterop": true,
17
- "composite": true,
18
- "skipLibCheck": true,
19
- "types": [
20
- "bun"
21
- ],
22
- "forceConsistentCasingInFileNames": true,
23
- "resolveJsonModule": true,
24
- "declaration": true,
25
- "declarationMap": true,
26
- "emitDeclarationOnly": true,
27
- "outDir": "./dist",
28
- },
29
- "include": [
30
- "src/**/*.ts",
31
- "tests/**/*.ts",
32
- "scripts/**/*.ts",
33
- "scripts/**/*.json"
34
- ],
35
- "exclude": [
36
- "node_modules",
37
- "dist"
38
- ]
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "lib": [
6
+ "ESNext"
7
+ ],
8
+ "moduleResolution": "bundler",
9
+ "strict": true,
10
+ "verbatimModuleSyntax": true,
11
+ "noUncheckedIndexedAccess": true,
12
+ "exactOptionalPropertyTypes": true,
13
+ "noImplicitOverride": true,
14
+ "isolatedDeclarations": true,
15
+ "esModuleInterop": true,
16
+ "composite": true,
17
+ "skipLibCheck": true,
18
+ "types": [
19
+ "bun"
20
+ ],
21
+ "forceConsistentCasingInFileNames": true,
22
+ "resolveJsonModule": true,
23
+ "declaration": true,
24
+ "declarationMap": true,
25
+ "emitDeclarationOnly": true,
26
+ "outDir": "./dist"
27
+ },
28
+ "include": [
29
+ "scripts/**/*.ts",
30
+ "scripts/**/*.json",
31
+ "src/**/*.ts",
32
+ "tests/**/*.ts"
33
+ ],
34
+ "exclude": [
35
+ "node_modules",
36
+ "dist"
37
+ ]
39
38
  }
package/dist/cli.d.ts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env node
2
- import { cpSync, readFileSync, renameSync, writeFileSync } from 'fs';
3
- import { resolve } from 'path';
4
- import { templatePath, changelogPath, buildinfoPath, readmePath } from './constants.js';
5
- try {
6
- const packageNameArgument = process.argv[2];
7
- if (!packageNameArgument)
8
- throw new Error('Package name argument is required. Usage: `create-ts-lib <package-name>`');
9
- const packageName = packageNameArgument.replace(/\\/g, '/');
10
- const destinationPath = resolve(process.cwd(), packageName);
11
- cpSync(templatePath, destinationPath, { recursive: true });
12
- cpSync(changelogPath, resolve(destinationPath, 'CHANGELOG-template.md'));
13
- cpSync(buildinfoPath, resolve(destinationPath, 'buildinfo-template.txt'));
14
- cpSync(readmePath, resolve(destinationPath, 'README-template.md'));
15
- const packageJsonPath = resolve(destinationPath, 'package.json');
16
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
17
- packageJson.name = packageName;
18
- writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
19
- renameSync(resolve(destinationPath, 'gitignore'), resolve(destinationPath, '.gitignore'));
20
- console.log(`Template has been successfully instantiated at '${destinationPath}' with package name '${packageName}'.`);
21
- }
22
- catch (error) {
23
- const err = error instanceof Error ? error : new Error(String(error));
24
- console.error('Error:', err.message);
25
- process.exit(1);
26
- }
@@ -1,7 +0,0 @@
1
- export declare const packageUrl: URL;
2
- export declare const packagePath: string;
3
- export declare const templatePath: string;
4
- export declare const changelogPath: string;
5
- export declare const buildinfoPath: string;
6
- export declare const readmePath: string;
7
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,EAAE,GAAqC,CAAC;AAC/D,eAAO,MAAM,WAAW,EAAE,MAA2C,CAAC;AAEtE,eAAO,MAAM,YAAY,EAAE,MAA0C,CAAC;AAEtE,eAAO,MAAM,aAAa,EAAE,MAA6C,CAAC;AAC1E,eAAO,MAAM,aAAa,EAAE,MAA8C,CAAC;AAC3E,eAAO,MAAM,UAAU,EAAE,MAA0C,CAAC"}
package/dist/constants.js DELETED
@@ -1,8 +0,0 @@
1
- import { resolve } from 'path';
2
- import { fileURLToPath } from 'url';
3
- export const packageUrl = new URL('../', import.meta.url);
4
- export const packagePath = resolve(fileURLToPath(packageUrl));
5
- export const templatePath = resolve(packagePath, 'template/');
6
- export const changelogPath = resolve(packagePath, 'CHANGELOG.md');
7
- export const buildinfoPath = resolve(packagePath, 'buildinfo.txt');
8
- export const readmePath = resolve(packagePath, 'README.md');
@@ -1,19 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "module": "nodenext",
6
- "moduleResolution": "nodenext",
7
- "emitDeclarationOnly": false,
8
- },
9
- "include": [
10
- "src/**/*.ts"
11
- ],
12
- "exclude": [
13
- "src/dev.ts",
14
- "node_modules",
15
- "dist",
16
- "tests",
17
- "scripts"
18
- ]
19
- }