@temir.ra/create-test115 0.0.12 → 0.0.14
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 +46 -0
- package/CHANGELOG.md.template +5 -0
- package/gitignore +2 -0
- package/package.json +12 -2
- package/scripts/build-cdn-map.json +1 -0
- package/scripts/build-cdn.ts +158 -0
- package/scripts/buildinfo.ts +25 -0
- package/src/buildinfo.ts +2 -0
- package/src/dev.ts +5 -0
- package/src/index.ts +0 -0
- package/tests/buildinfo.test.ts +20 -0
- package/tsconfig.build.json +18 -0
- package/tsconfig.json +35 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Version 0
|
|
2
|
+
|
|
3
|
+
## next
|
|
4
|
+
|
|
5
|
+
1. Updated `scripts/buildinfo.ts` to use `join` from `path` module for better cross-platform compatibility.
|
|
6
|
+
2. Added `scripts/build-cdn.ts` to generate a bundled version of the library for CDN usage.
|
|
7
|
+
3. Added `scripts/build-cdn-map.json` to configure import path rewrites for the CDN build.
|
|
8
|
+
4. Cleaned up legacy fields `main`, `module`, and `types` from `package.json` to rely solely on the `exports` field for module resolution.
|
|
9
|
+
5. Added `browser` condition to the `exports` field in `package.json` to specify the bundled version for CDN usage.
|
|
10
|
+
6. Added `src/dev.ts` as a development entry point for testing and experimentation during development.
|
|
11
|
+
7. Added QoL `clean` and `test` scripts to `package.json`.
|
|
12
|
+
8. Updated `build` workflow in `package.json`. Now it runs `build:lib` to create JavaScript and declaration files, then runs `build:cdn` to create the bundled version for CDN, and finally runs `build:assets` as a placeholder for any future asset build steps.
|
|
13
|
+
9. Added `description` metadata field to `package.json`.
|
|
14
|
+
10. Updated `tsconfig.json` and `tsconfig.build.json` with opiniated settings for better development, build, and publishing experience.
|
|
15
|
+
11. Added documentation for custom scripts and rationale for the selected values in `tsconfig.json`, `tsconfig.build.json`, and `package.json`.
|
|
16
|
+
12. Updated Quick Start instructions to reflect the new scripts and workflow.
|
|
17
|
+
13. Renamed `README.md` and `CHANGELOG.md` to `README.md.template` and `CHANGELOG.md.template` respectively, and added a `bun-create` configuration in `package.json` to rename them back during project creation.
|
|
18
|
+
14. Added `gitignore` (note the missing dot) to the template to ensure that generated projects have a proper `.gitignore` file.
|
|
19
|
+
|
|
20
|
+
## 0.2.0
|
|
21
|
+
|
|
22
|
+
1. Added `tests/` directory for unit tests using Bun's built-in test runner.
|
|
23
|
+
2. Updated `tsconfig.json` to include `tests/` in the `include` array to allow TypeScript to recognize test files during development, while still excluding them from the build output using `tsconfig.build.json`.
|
|
24
|
+
3. Updated `tsconfig.build.json` to exclude `tests/` to ensure that test files are not included in the build output.
|
|
25
|
+
4. Updated `tsconfig.json` to include `baseUrl` and `paths` for better module resolution and cleaner import statements in the source code.
|
|
26
|
+
|
|
27
|
+
## 0.1.4
|
|
28
|
+
|
|
29
|
+
1. Introduced `tsconfig.build.json` to separate build-specific TypeScript configuration from development configuration, allowing for more tailored settings for each use case.
|
|
30
|
+
2. Updated scripts in `package.json` to utilize `tsconfig.build.json` for the build process, ensuring that the build is optimized and does not include unnecessary files or settings meant for development.
|
|
31
|
+
|
|
32
|
+
## 0.1.3
|
|
33
|
+
|
|
34
|
+
1. Added `--no-git` to `bun create` command in Quick Start instructions to allow users to choose when to initialize git repository.
|
|
35
|
+
|
|
36
|
+
## 0.1.2
|
|
37
|
+
|
|
38
|
+
1. Added `--no-install` to `bun create` command in Quick Start instructions to allow users to choose when to install dependencies.
|
|
39
|
+
|
|
40
|
+
## 0.1.1
|
|
41
|
+
|
|
42
|
+
1. Fixed github user in Quick Start instructions.
|
|
43
|
+
|
|
44
|
+
## 0.1.0
|
|
45
|
+
|
|
46
|
+
1. First version of the template.
|
package/gitignore
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temir.ra/create-test115",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -12,7 +12,17 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"
|
|
15
|
+
"src",
|
|
16
|
+
"tests",
|
|
17
|
+
"scripts",
|
|
18
|
+
"tsconfig.json",
|
|
19
|
+
"tsconfig.build.json",
|
|
20
|
+
"README.md",
|
|
21
|
+
"README.md.template",
|
|
22
|
+
"CHANGELOG.md",
|
|
23
|
+
"CHANGELOG.md.template",
|
|
24
|
+
"gitignore",
|
|
25
|
+
"package.json"
|
|
16
26
|
],
|
|
17
27
|
"bun-create": {
|
|
18
28
|
"preinstall": [
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import CDN_MAP from 'scripts/build-cdn-map.json';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
interface ExportConditions {
|
|
7
|
+
|
|
8
|
+
[key: string]: string | undefined;
|
|
9
|
+
|
|
10
|
+
import?: string;
|
|
11
|
+
types?: string;
|
|
12
|
+
browser?: string;
|
|
13
|
+
entrypoint?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface DependencyMap {
|
|
17
|
+
[packageName: string]: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface PackageManifest {
|
|
21
|
+
version: string;
|
|
22
|
+
exports?: Record<string, ExportConditions>;
|
|
23
|
+
dependencies?: DependencyMap;
|
|
24
|
+
devDependencies?: DependencyMap;
|
|
25
|
+
peerDependencies?: DependencyMap;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getManifest(packageIdentifier?: string): PackageManifest {
|
|
29
|
+
|
|
30
|
+
const manifestPath = packageIdentifier
|
|
31
|
+
? join('node_modules', packageIdentifier, 'package.json')
|
|
32
|
+
: 'package.json';
|
|
33
|
+
|
|
34
|
+
let manifest: PackageManifest;
|
|
35
|
+
try {
|
|
36
|
+
manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
37
|
+
} catch {
|
|
38
|
+
if (packageIdentifier)
|
|
39
|
+
throw new Error("[build-cdn] Could not read manifest for '" + packageIdentifier + "' at '" + manifestPath + "'. Is it installed?");
|
|
40
|
+
else
|
|
41
|
+
throw new Error("[build-cdn] Could not read package manifest at '" + manifestPath + "'.");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return manifest;
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getManifestEntrypoints(packageManifest: PackageManifest): string[] {
|
|
49
|
+
|
|
50
|
+
const exports = packageManifest.exports;
|
|
51
|
+
if (!exports) throw new Error('[build-cdn] No exports field found in package.json.');
|
|
52
|
+
|
|
53
|
+
const entrypoints = Object.entries(exports)
|
|
54
|
+
.map(([key, conditions]) => {
|
|
55
|
+
if (!conditions.entrypoint) throw new Error(`[build-cdn] Export '${key}' does not have an 'entrypoint' condition.`);
|
|
56
|
+
return conditions.entrypoint;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return entrypoints;
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string): string {
|
|
64
|
+
|
|
65
|
+
let version: string | undefined;
|
|
66
|
+
if (packageIdentifier) {
|
|
67
|
+
|
|
68
|
+
const dependencies = {
|
|
69
|
+
...manifest.dependencies,
|
|
70
|
+
...manifest.devDependencies,
|
|
71
|
+
...manifest.peerDependencies,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
version = dependencies[packageIdentifier];
|
|
75
|
+
if (!version) throw new Error(`[build-cdn] Package '${packageIdentifier}' is not listed in dependencies.`);
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
if (!manifest.version) throw new Error('[build-cdn] Package manifest does not contain a version field.');
|
|
80
|
+
version = manifest.version;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return version;
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function resolveCdnUrl(importSpecifier: string, urlTemplate: string): string {
|
|
88
|
+
const manifest = getManifest();
|
|
89
|
+
const version = getPackageVersion(manifest, importSpecifier);
|
|
90
|
+
return urlTemplate.replace('<VERSION>', version);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const cdnRewritePlugin = {
|
|
94
|
+
name: 'cdn-rewrite',
|
|
95
|
+
setup(build: any) {
|
|
96
|
+
|
|
97
|
+
const resolved = new Map<string, string>();
|
|
98
|
+
for (const [importSpecifier, urlTemplate] of Object.entries(CDN_MAP) as [string, string][]) {
|
|
99
|
+
const url = resolveCdnUrl(importSpecifier, urlTemplate);
|
|
100
|
+
resolved.set(importSpecifier, url);
|
|
101
|
+
console.log(`[cdn-rewrite] '${importSpecifier}' → '${url}'`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
build.onResolve({ filter: /.*/ }, (args: any) => {
|
|
105
|
+
const url = resolved.get(args.path);
|
|
106
|
+
if (url) return { path: url, external: true };
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
const entrypoints = getManifestEntrypoints(getManifest());
|
|
114
|
+
console.log('[build-cdn] Entrypoints:', entrypoints);
|
|
115
|
+
|
|
116
|
+
let buildResult;
|
|
117
|
+
|
|
118
|
+
console.log('[build-cdn] Starting ESM CDN bundle build...');
|
|
119
|
+
buildResult = await Bun.build({
|
|
120
|
+
entrypoints,
|
|
121
|
+
outdir: 'dist',
|
|
122
|
+
naming: '[dir]/[name].bundle.[ext]',
|
|
123
|
+
target: 'browser',
|
|
124
|
+
format: 'esm',
|
|
125
|
+
minify: true,
|
|
126
|
+
sourcemap: 'external',
|
|
127
|
+
plugins: [cdnRewritePlugin],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
if (!buildResult.success) {
|
|
131
|
+
console.error('[build-cdn] Build failed:');
|
|
132
|
+
for (const message of buildResult.logs) {
|
|
133
|
+
console.error(message);
|
|
134
|
+
}
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
console.log('[build-cdn] ESM CDN bundle build completed successfully.');
|
|
138
|
+
|
|
139
|
+
console.log('[build-cdn] Starting IIFE CDN bundle build...');
|
|
140
|
+
buildResult = await Bun.build({
|
|
141
|
+
entrypoints,
|
|
142
|
+
outdir: 'dist',
|
|
143
|
+
naming: '[dir]/[name].iife.[ext]',
|
|
144
|
+
target: 'browser',
|
|
145
|
+
format: 'iife',
|
|
146
|
+
minify: true,
|
|
147
|
+
sourcemap: 'external',
|
|
148
|
+
plugins: [cdnRewritePlugin],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
if (!buildResult.success) {
|
|
152
|
+
console.error('[build-cdn] Build failed:');
|
|
153
|
+
for (const message of buildResult.logs) {
|
|
154
|
+
console.error(message);
|
|
155
|
+
}
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
console.log('[build-cdn] IIFE CDN bundle build completed successfully.');
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { writeFileSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const BUILD_INFO_FILE = join('src', 'buildinfo.ts');
|
|
7
|
+
const GIT_COMMAND = 'git rev-parse --short HEAD';
|
|
8
|
+
|
|
9
|
+
const version = process.env.npm_package_version ?? '0.0.0';
|
|
10
|
+
|
|
11
|
+
let gitHash = '';
|
|
12
|
+
try {
|
|
13
|
+
gitHash = execSync(GIT_COMMAND, { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
14
|
+
.toString()
|
|
15
|
+
.trim();
|
|
16
|
+
} catch { }
|
|
17
|
+
|
|
18
|
+
const buildInfo = gitHash ? `${version}+${gitHash}` : version;
|
|
19
|
+
|
|
20
|
+
writeFileSync(
|
|
21
|
+
BUILD_INFO_FILE,
|
|
22
|
+
`// auto-generated by scripts/buildinfo.ts\nexport const buildInfo = '${buildInfo}';\n`
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
console.log(`'${BUILD_INFO_FILE}' has been updated with build info: ${buildInfo}`);
|
package/src/buildinfo.ts
ADDED
package/src/dev.ts
ADDED
package/src/index.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, it, expect } from 'bun:test';
|
|
2
|
+
import { buildInfo } from '@/buildinfo';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
describe('buildInfo', () => {
|
|
6
|
+
|
|
7
|
+
it('should follow semantic versioning format with optional commit hash', () => {
|
|
8
|
+
expect(buildInfo).toMatch(/^\d+\.\d+\.\d+(\+[0-9a-f]+)?$/);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should not contain whitespace', () => {
|
|
12
|
+
expect(buildInfo).not.toMatch(/\s/);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should not be empty or dash', () => {
|
|
16
|
+
expect(buildInfo.length).toBeGreaterThan(0);
|
|
17
|
+
expect(buildInfo).not.toBe('-');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"moduleResolution": "nodenext",
|
|
6
|
+
"emitDeclarationOnly": false,
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"src/**/*.ts"
|
|
10
|
+
],
|
|
11
|
+
"exclude": [
|
|
12
|
+
"src/dev.ts",
|
|
13
|
+
"node_modules",
|
|
14
|
+
"dist",
|
|
15
|
+
"tests",
|
|
16
|
+
"scripts"
|
|
17
|
+
]
|
|
18
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"lib": [
|
|
6
|
+
"ES2022",
|
|
7
|
+
"DOM"
|
|
8
|
+
],
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"declarationMap": true,
|
|
17
|
+
"emitDeclarationOnly": true,
|
|
18
|
+
"outDir": "./dist",
|
|
19
|
+
"baseUrl": ".",
|
|
20
|
+
"paths": {
|
|
21
|
+
"@/*": [
|
|
22
|
+
"src/*"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"include": [
|
|
27
|
+
"src/**/*.ts",
|
|
28
|
+
"tests/**/*.ts",
|
|
29
|
+
"scripts/**/*.ts"
|
|
30
|
+
],
|
|
31
|
+
"exclude": [
|
|
32
|
+
"node_modules",
|
|
33
|
+
"dist"
|
|
34
|
+
]
|
|
35
|
+
}
|