@temir.ra/create-test115 0.0.12

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/README.md ADDED
@@ -0,0 +1,289 @@
1
+ # Introduction
2
+
3
+ This package serves as a template for creating Bun libraries. It includes a basic setup with TypeScript, build scripts, and versioning information.
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Quick Start](#quick-start)
8
+ 2. [Documentation](#documentation)
9
+ 1. [`tsconfig.json` and `tsconfig.build.json`](#tsconfigjson-and-tsconfigbuildjson)
10
+ 2. [`package.json`](#packagejson)
11
+ 3. [Script `scripts/buildinfo.ts`](#script-scriptsbuildinfots)
12
+ 4. [Script `scripts/build-cdn.ts`](#script-scriptsbuild-cdn-ts)
13
+ 5. [CDN Map `scripts/build-cdn-map.json`](#cdn-map-scriptsbuild-cdn-mapjson)
14
+ 3. [DevOps](#devops)
15
+ 1. [Change Management](#change-management)
16
+ 2. [Publish](#publish)
17
+
18
+ # Quick Start
19
+
20
+ ```bash
21
+ # placeholder:
22
+ # <PACKAGE: <PACKAGE>
23
+
24
+ bun create temir-ra/bun-lib-template --no-install --no-git <PACKAGE>
25
+ cd <PACKAGE>
26
+ bun install
27
+
28
+ bun run dev
29
+ bun run test
30
+
31
+ bun run build
32
+
33
+ bun publish
34
+ ```
35
+
36
+ # Documentation
37
+
38
+ `README-template.md` and `CHANGELOG-template.md` are the actual documentation files for this template package. Whereas `README.md` and `CHANGELOG.md` are copied as part of the package creation process and should be modified by the user to reflect the specifics of their library.
39
+
40
+ ## `tsconfig.json` and `tsconfig.build.json`
41
+
42
+ ```json
43
+ {
44
+
45
+ "compilerOptions": {
46
+
47
+ // supported JavaScript features and syntax in the emitted JavaScript files
48
+ // ES2022 is a reasonable modern baseline
49
+ "target": "ES2022",
50
+
51
+ // how import and export statements are written in the emitted JavaScript files
52
+ // ESNext emits standard ES module syntax unchanged
53
+ "module": "ESNext",
54
+
55
+ // available built-in types
56
+ "lib": [
57
+ "ES2022", // standard JavaScript runtime APIs
58
+ "DOM" // browser globals or import.meta.url
59
+ ],
60
+
61
+ // permissive about file extensions in import statements
62
+ // `tsconfig.build.json` switches to a stricter resolution mode
63
+ "moduleResolution": "bundler",
64
+
65
+ // collection of type-safety checks
66
+ "strict": true,
67
+
68
+ // compatibility shims that make it easier to import CommonJS modules as if they were ES modules
69
+ "esModuleInterop": true,
70
+
71
+ // do not type-check `.d.ts` files in `node_modules/`
72
+ "skipLibCheck": true,
73
+
74
+ // enforce consistent casing across import statements
75
+ "forceConsistentCasingInFileNames": true,
76
+
77
+ // allow importing JSON files as modules and infer the full type of the JSON structure
78
+ "resolveJsonModule": true,
79
+
80
+ // generate .d.ts type declaration files alongside the JavaScript output
81
+ "declaration": true,
82
+ // allow a consumer's editor to "go to definition" on something from the library
83
+ "declarationMap": true,
84
+
85
+ // prevents tsc from emitting any JavaScript files
86
+ // during development, rely on executing environment to handle TypeScript directly
87
+ // during build, use `tsconfig.build.json` to override this setting and emit JavaScript files for distribution
88
+ "emitDeclarationOnly": true,
89
+
90
+ // the directory where the emitted JavaScript and declaration files will be placed when building the library for distribution
91
+ // matches the `files` field in `package.json` that determines what gets published
92
+ "outDir": "./dist",
93
+
94
+ // the base directory to resolve non-relative module imports
95
+ "baseUrl": ".",
96
+
97
+ // a mapping of module import paths to physical paths in the project
98
+ // `paths` is a TypeScript-only feature - it must not be used in import statements in `src/` files
99
+ "paths": {
100
+ "@/*": [
101
+ "src/*"
102
+ ]
103
+ }
104
+
105
+ },
106
+
107
+ // files to be included/excluded by the TypeScript compiler and the development environment
108
+ // `tsconfig.build.json` overrides these settings to include only `src/` files
109
+ "include": [
110
+ "src/**/*.ts",
111
+ "tests/**/*.ts",
112
+ "scripts/**/*.ts"
113
+ ],
114
+ "exclude": [
115
+ "node_modules",
116
+ "dist"
117
+ ]
118
+
119
+ }
120
+ ```
121
+
122
+ During development, the `tsconfig.json` configuration prevents emitting JavaScript files and relies on the executing environment to handle TypeScript directly. The `include` and `exclude` settings ensure that all relevant TypeScript files are included in the development environment.
123
+
124
+ When building the library for distribution, the `tsconfig.build.json` configuration overrides the settings to emit JavaScript files and include only the `src/` files.
125
+
126
+ ```json
127
+ {
128
+
129
+ "extends": "./tsconfig.json",
130
+
131
+ "compilerOptions": {
132
+
133
+ // `nodenext` is the strictest and most forward-compatible ESM mode
134
+ // imports must include explicit `.js` file extensions
135
+ "module": "nodenext",
136
+ "moduleResolution": "nodenext",
137
+
138
+ // emit both JavaScript files and declaration files for distribution
139
+ "emitDeclarationOnly": false,
140
+
141
+ },
142
+
143
+ // include only the source files for the build, excluding tests and scripts
144
+ "include": [
145
+ "src/**/*.ts"
146
+ ],
147
+ "exclude": [
148
+ "node_modules",
149
+ "dist",
150
+ "tests",
151
+ "scripts"
152
+ ]
153
+
154
+ }
155
+ ```
156
+
157
+ ## `package.json`
158
+
159
+ ```json
160
+ {
161
+ "name": "package",
162
+ "version": "0.0.0",
163
+ "description": "",
164
+
165
+ // "module" makes every `.js` file in the package to be treated as an ES module unless explicitly named `.cjs`
166
+ "type": "module",
167
+
168
+ // runtime consults "exports" to find the actual file to load
169
+ // "import" condition is used by ESM consumers
170
+ // "types" condition is used by TypeScript to find the declaration files
171
+ // "browser" condition is used by CDN infrastructure
172
+ // "entrypoint" is a custom condition used by the build script to find the entry point for the CDN build
173
+ "exports": {
174
+ ".": {
175
+ "entrypoint": "./src/index.ts",
176
+ "browser": "./dist/index.bundle.js",
177
+ "import": "./dist/index.js",
178
+ "types": "./dist/index.d.ts"
179
+ }
180
+ },
181
+
182
+ // files to include in the published package
183
+ "files": [
184
+ "dist"
185
+ ],
186
+
187
+ "scripts": {
188
+
189
+ // cleans the `dist/` directory before building
190
+ "clean": "rm -rf dist/",
191
+
192
+ // overwrites `src/buildinfo.ts` with the current version and git hash (if available)
193
+ "prebuild": "bun run scripts/buildinfo.ts",
194
+
195
+ // runs all tests
196
+ "test": "bun test",
197
+
198
+ // runs all build steps in sequence
199
+ "build": "bun run build:lib && bun run build:cdn && bun run build:assets",
200
+
201
+ // uses `tsconfig.build.json` to compile the TypeScript source files
202
+ "build:lib": "tsc --project tsconfig.build.json",
203
+
204
+ // bundles the library for CDN distribution in both ESM and IIFE formats
205
+ "build:cdn": "bun run scripts/build-cdn.ts",
206
+
207
+ // placeholder for any asset build steps (e.g. copying static files, generating documentation, etc.)
208
+ "build:assets": "echo 'no assets to build'",
209
+
210
+ // type checks the TypeScript source files without emitting any output
211
+ "typecheck": "tsc --noEmit",
212
+
213
+ // runs the development file
214
+ "dev": "bun run --watch src/dev.ts"
215
+
216
+ },
217
+ "devDependencies": {
218
+ "@types/bun": "latest",
219
+ "typescript": "^5.9.3"
220
+ }
221
+ }
222
+ ```
223
+
224
+ ## Script `scripts/buildinfo.ts`
225
+
226
+ This script overwrites `src/buildinfo.ts` with the current version from `package.json` and the current git hash (if available).
227
+
228
+ ## Script `scripts/build-cdn.ts`
229
+
230
+ This script bundles the library for CDN distribution in both ESM and IIFE formats. It reads the `exports` field from `package.json` to determine the entry points for the library and generates bundled files in the `dist/` directory. A custom condition `entrypoint` is used in the `exports` field to specify the entry point for the CDN build.
231
+
232
+ During the bundling process, the import paths in the source files can be rewritten to point to a CDN URL of a package, instead of using the package name that would be resolved from `node_modules/`.
233
+
234
+ The list of import paths to rewrite and their corresponding CDN URLs can be configured in the `scripts/build-cdn-map.json` file.
235
+
236
+ ## CDN Map `scripts/build-cdn-map.json`
237
+
238
+ This JSON file contains a mapping of module import paths to their corresponding CDN URLs. During the CDN build process, if an import path in the source files matches a key in this map, it will be replaced with the corresponding CDN URL in the bundled output.
239
+
240
+ The URL can contain the placeholder `<VERSION>` which will be replaced with the current version of that package from `package.json`.
241
+
242
+ ```json
243
+ {
244
+ "package-name": "https://cdn.jsdelivr.net/npm/package-name@<VERSION>/dist/index.bundle.js"
245
+ }
246
+ ```
247
+
248
+ - Keys are the import specifiers as they appear in source code.
249
+ - Values are CDN URLs. The URL can contain the placeholder `<VERSION>` which will be replaced with the current version of that package from `package.json`.
250
+
251
+ # DevOps
252
+
253
+ ## Change Management
254
+
255
+ 1. Create a new branch for the change.
256
+ 2. Make the changes and commit them to the branch.
257
+ 3. Add an entry for the new version in [`CHANGELOG-template.md`](CHANGELOG-template.md).
258
+ 4. Pull & publish request the branch.
259
+
260
+ ## Publish
261
+
262
+ ### `npmjs.org`
263
+
264
+ ⚠️ Either run `npm login` or set up `~/.npmrc` or `bunfig.toml` with the appropriate auth token before running the publish command.
265
+
266
+ ```powershell
267
+ bun publish --registry https://registry.npmjs.org/ --access public
268
+ ```
269
+
270
+ ### Custom registry with `bun`
271
+
272
+ ```bash
273
+ # placeholder:
274
+ # <SCOPE_WITHOUT_AT: <SCOPE_WITHOUT_AT>
275
+ # <REGISTRY_URL: <REGISTRY_URL>
276
+ # <BUN_PUBLISH_AUTH_TOKEN: <BUN_PUBLISH_AUTH_TOKEN>
277
+ ```
278
+
279
+ `bunfig.toml`:
280
+
281
+ ```toml
282
+ [install.scopes]
283
+ <SCOPE_WITHOUT_AT> = { url = "<REGISTRY_URL>", token = "$BUN_PUBLISH_AUTH_TOKEN" }
284
+ ```
285
+
286
+ ```powershell
287
+ $env:BUN_PUBLISH_AUTH_TOKEN = "<BUN_PUBLISH_AUTH_TOKEN>"
288
+ bun publish
289
+ ```
@@ -0,0 +1,59 @@
1
+ # Introduction
2
+
3
+ *&lt;INTRO TEXT&gt;*
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Quick Start](#quick-start)
8
+ 2. [Documentation](#documentation)
9
+ 3. [DevOps](#devops)
10
+ 1. [Change Management](#change-management)
11
+ 2. [Publish](#publish)
12
+
13
+ # Quick Start
14
+
15
+ *&lt;QUICK START INSTRUCTIONS&gt;*
16
+
17
+ # Documentation
18
+
19
+ *&lt;DOCUMENTATION&gt;*
20
+
21
+ # DevOps
22
+
23
+ ## Change Management
24
+
25
+ 1. Create a new branch for the change.
26
+ 2. Make the changes and commit them to the branch.
27
+ 3. Bump the version in [`package.json`](package.json).
28
+ 4. Add an entry for the new version in [`CHANGELOG.md`](CHANGELOG.md).
29
+ 5. Pull request the branch.
30
+
31
+ ## Publish
32
+
33
+ ### bun
34
+
35
+ ```bash
36
+ # placeholder:
37
+ # <SCOPE_WITHOUT_AT: <SCOPE_WITHOUT_AT>
38
+ # <REGISTRY_URL: <REGISTRY_URL>
39
+ # <BUN_PUBLISH_AUTH_TOKEN: <BUN_PUBLISH_AUTH_TOKEN>
40
+ ```
41
+
42
+ `bunfig.toml`:
43
+
44
+ ```toml
45
+ [install.scopes]
46
+ <SCOPE_WITHOUT_AT> = { url = "<REGISTRY_URL>", token = "$BUN_PUBLISH_AUTH_TOKEN" }
47
+ ```
48
+
49
+ ```powershell
50
+ $env:BUN_PUBLISH_AUTH_TOKEN = "<BUN_PUBLISH_AUTH_TOKEN>"
51
+ bun publish
52
+ ```
53
+
54
+ ### npm
55
+
56
+ ```powershell
57
+ npm login --registry https://registry.npmjs.org/
58
+ npm publish --registry https://registry.npmjs.org/ --access public
59
+ ```
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@temir.ra/create-test115",
3
+ "version": "0.0.12",
4
+ "description": "",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "entrypoint": "./src/index.ts",
9
+ "browser": "./dist/index.bundle.js",
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "bun-create": {
18
+ "preinstall": [
19
+ "mv README.md README-template.md",
20
+ "mv README.md.template README.md",
21
+ "mv CHANGELOG.md CHANGELOG-template.md",
22
+ "mv CHANGELOG.md.template CHANGELOG.md"
23
+ ]
24
+ },
25
+ "scripts": {
26
+ "clean": "rm -rf dist/",
27
+ "prebuild": "bun run scripts/buildinfo.ts",
28
+ "test": "bun test",
29
+ "build": "bun run build:lib && bun run build:cdn && bun run build:assets",
30
+ "build:lib": "tsc --project tsconfig.build.json",
31
+ "build:cdn": "bun run scripts/build-cdn.ts",
32
+ "build:assets": "echo 'no assets to build'",
33
+ "typecheck": "tsc --noEmit",
34
+ "dev": "bun run --watch src/dev.ts"
35
+ },
36
+ "devDependencies": {
37
+ "@types/bun": "latest",
38
+ "typescript": "^5.9.3"
39
+ }
40
+ }