bunup 0.8.42 → 0.8.44

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.
@@ -1,4 +1,4 @@
1
- import { BuildContext, BunupPlugin, MaybePromise, Plugin } from "../chunk-4gbrfagt";
1
+ import { BuildContext, BunupPlugin, MaybePromise, Plugin } from "./chunk-4gbrfagt";
2
2
  /**
3
3
  * A plugin that provides shims for Node.js globals and ESM/CJS interoperability.
4
4
  *
@@ -0,0 +1,268 @@
1
+ // @bun
2
+ import {
3
+ getPackageForPlugin
4
+ } from "./chunk-6gvmfnmt.js";
5
+ import {
6
+ cleanPath,
7
+ isDirectoryPath,
8
+ logger
9
+ } from "./chunk-c1eyecm3.js";
10
+
11
+ // src/constants/re.ts
12
+ var JS_RE = /\.(js|jsx|cjs|mjs)$/;
13
+ var TS_RE = /\.(ts|tsx|mts|cts)$/;
14
+ var DTS_RE = /\.(d\.(ts|mts|cts))$/;
15
+ var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
16
+ var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
17
+ var CSS_RE = /\.(css)$/;
18
+
19
+ // src/plugins/built-in/shims.ts
20
+ function shims() {
21
+ return {
22
+ type: "bun",
23
+ name: "shims",
24
+ plugin: {
25
+ name: "bunup:shims",
26
+ setup(build) {
27
+ const isNodeCompatibleTarget = build.config.target === "node" || build.config.target === "bun";
28
+ const isEsm = build.config.format === "esm";
29
+ const isCjs = build.config.format === "cjs";
30
+ if (!isNodeCompatibleTarget || !isEsm && !isCjs) {
31
+ return;
32
+ }
33
+ build.config.define = {
34
+ ...build.config.define,
35
+ ...isCjs && {
36
+ "import.meta.url": "importMetaUrl"
37
+ }
38
+ };
39
+ build.onLoad({ filter: JS_TS_RE }, async ({ path }) => {
40
+ const content = await Bun.file(path).text();
41
+ let shimCode = "";
42
+ if (isEsm && (/\b__dirname\b/.test(content) || /\b__filename\b/.test(content))) {
43
+ shimCode = `import { fileURLToPath } from 'url';
44
+ import { dirname } from 'path';
45
+
46
+ const __filename = fileURLToPath(import.meta.url);
47
+ const __dirname = dirname(__filename);
48
+
49
+ `;
50
+ }
51
+ if (isCjs && /\bimport\.meta\.url\b/.test(content)) {
52
+ shimCode = `import { pathToFileURL } from 'url';
53
+
54
+ const importMetaUrl = pathToFileURL(__filename).href;
55
+
56
+ `;
57
+ }
58
+ if (!shimCode)
59
+ return;
60
+ const lines = content.split(`
61
+ `);
62
+ const firstLine = lines[0];
63
+ const restLines = lines.slice(1);
64
+ return {
65
+ contents: [firstLine, shimCode, ...restLines].join(`
66
+ `)
67
+ };
68
+ });
69
+ }
70
+ }
71
+ };
72
+ }
73
+ // src/plugins/built-in/exports.ts
74
+ import path from "path";
75
+ function exports(options = {}) {
76
+ return {
77
+ type: "bunup",
78
+ name: "exports",
79
+ hooks: {
80
+ onBuildDone: async (ctx) => {
81
+ const { output, options: buildOptions, meta } = ctx;
82
+ if (!meta.packageJson.path || !meta.packageJson.data) {
83
+ return;
84
+ }
85
+ try {
86
+ const { exportsField, entryPoints } = generateExportsFields(output.files);
87
+ const files = Array.isArray(meta.packageJson.data.files) ? [
88
+ ...new Set([
89
+ ...meta.packageJson.data.files,
90
+ buildOptions.outDir
91
+ ])
92
+ ] : [buildOptions.outDir];
93
+ const mergedExports = { ...exportsField };
94
+ if (options.customExports) {
95
+ for (const [key, value] of Object.entries(options.customExports(ctx) ?? {})) {
96
+ if (typeof value === "string") {
97
+ mergedExports[key] = value;
98
+ } else {
99
+ const existingExport = mergedExports[key];
100
+ if (typeof existingExport === "object" && existingExport !== null) {
101
+ mergedExports[key] = {
102
+ ...existingExport,
103
+ ...value
104
+ };
105
+ } else {
106
+ mergedExports[key] = value;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ const { main, module, types, ...restPackageJson } = meta.packageJson.data;
112
+ const newPackageJson = {
113
+ name: meta.packageJson.data.name,
114
+ description: meta.packageJson.data.description,
115
+ version: meta.packageJson.data.version,
116
+ type: meta.packageJson.data.type,
117
+ private: meta.packageJson.data.private,
118
+ files,
119
+ ...entryPoints,
120
+ exports: mergedExports
121
+ };
122
+ for (const key in restPackageJson) {
123
+ if (Object.prototype.hasOwnProperty.call(restPackageJson, key) && !Object.prototype.hasOwnProperty.call(newPackageJson, key)) {
124
+ newPackageJson[key] = restPackageJson[key];
125
+ }
126
+ }
127
+ await Bun.write(meta.packageJson.path, JSON.stringify(newPackageJson, null, 2));
128
+ } catch {
129
+ logger.error("Failed to update package.json");
130
+ }
131
+ }
132
+ }
133
+ };
134
+ }
135
+ function generateExportsFields(files) {
136
+ const exportsField = {};
137
+ const entryPoints = {};
138
+ const filteredFiles = filterFiles(files);
139
+ for (const file of filteredFiles) {
140
+ const exportType = formatToExportField(file.format, file.dts);
141
+ const relativePath = `./${cleanPath(file.relativePathToRootDir)}`;
142
+ const exportKey = getExportKey(cleanPath(file.relativePathToOutputDir));
143
+ exportsField[exportKey] = {
144
+ ...exportsField[exportKey],
145
+ [exportType]: relativePath
146
+ };
147
+ }
148
+ for (const field of Object.keys(exportsField["."] ?? {})) {
149
+ const entryPoint = exportFieldToEntryPoint(field);
150
+ entryPoints[entryPoint] = exportsField["."][field];
151
+ }
152
+ return { exportsField, entryPoints };
153
+ }
154
+ function filterFiles(files) {
155
+ return files.filter((file) => JS_DTS_RE.test(file.fullPath) && file.kind === "entry-point");
156
+ }
157
+ function getExportKey(relativePathToOutputDir) {
158
+ const pathSegments = cleanPath(removeExtension(relativePathToOutputDir)).split("/");
159
+ if (pathSegments.length === 1 && pathSegments[0].startsWith("index")) {
160
+ return ".";
161
+ }
162
+ return `./${pathSegments.filter((p) => !p.startsWith("index")).join("/")}`;
163
+ }
164
+ function exportFieldToEntryPoint(exportField) {
165
+ return exportField === "types" ? "types" : exportField === "require" ? "main" : "module";
166
+ }
167
+ function formatToExportField(format, dts) {
168
+ return dts ? "types" : format === "esm" ? "import" : "require";
169
+ }
170
+ function removeExtension(filePath) {
171
+ const basename = path.basename(filePath);
172
+ const firstDotIndex = basename.indexOf(".");
173
+ if (firstDotIndex === -1) {
174
+ return filePath;
175
+ }
176
+ const nameWithoutExtensions = basename.slice(0, firstDotIndex);
177
+ const directory = path.dirname(filePath);
178
+ return directory === "." ? nameWithoutExtensions : path.join(directory, nameWithoutExtensions);
179
+ }
180
+ // src/plugins/built-in/copy.ts
181
+ import { join } from "path";
182
+ import { basename } from "path";
183
+ function copy(patterns, outPath) {
184
+ return {
185
+ type: "bunup",
186
+ name: "copy",
187
+ hooks: {
188
+ onBuildDone: async ({ options, meta }) => {
189
+ const destinationPath = outPath || options.outDir;
190
+ for (const pattern of patterns) {
191
+ const glob = new Bun.Glob(pattern);
192
+ for await (const filePath of glob.scan({
193
+ cwd: meta.rootDir,
194
+ dot: true
195
+ })) {
196
+ const sourceFile = Bun.file(join(meta.rootDir, filePath));
197
+ await Bun.write(outPath && isDirectoryPath(outPath) ? join(destinationPath, basename(filePath)) : destinationPath, sourceFile);
198
+ }
199
+ }
200
+ }
201
+ }
202
+ };
203
+ }
204
+ // src/plugins/built-in/inject-styles.ts
205
+ import path2 from "path";
206
+ function injectStyles(options) {
207
+ const { inject, ...transformOptions } = options ?? {};
208
+ return {
209
+ type: "bun",
210
+ name: "inject-styles",
211
+ plugin: {
212
+ name: "bunup:inject-styles",
213
+ async setup(build) {
214
+ const lightningcss = await getPackageForPlugin("lightningcss", "inject-styles");
215
+ build.onResolve({ filter: /^__inject-style$/ }, () => {
216
+ return {
217
+ path: "__inject-style",
218
+ namespace: "__inject-style"
219
+ };
220
+ });
221
+ build.onLoad({ filter: /^__inject-style$/, namespace: "__inject-style" }, () => {
222
+ return {
223
+ contents: `
224
+ export default function injectStyle(css) {
225
+ if (!css || typeof document === 'undefined') return
226
+
227
+ const head = document.head || document.getElementsByTagName('head')[0]
228
+ const style = document.createElement('style')
229
+ head.appendChild(style)
230
+
231
+ if (style.styleSheet) {
232
+ style.styleSheet.cssText = css
233
+ } else {
234
+ style.appendChild(document.createTextNode(css))
235
+ }
236
+ }
237
+ `,
238
+ loader: "js"
239
+ };
240
+ });
241
+ build.onLoad({ filter: CSS_RE }, async (args) => {
242
+ const source = await Bun.file(args.path).text();
243
+ const { code, warnings } = lightningcss.transform({
244
+ ...transformOptions,
245
+ filename: path2.basename(args.path),
246
+ code: Buffer.from(source),
247
+ minify: transformOptions.minify ?? (build.config.minify === true || typeof build.config.minify === "object" && build.config.minify.whitespace)
248
+ });
249
+ for (const warning of warnings) {
250
+ logger.warn(warning.message);
251
+ }
252
+ const stringifiedCode = JSON.stringify(code.toString());
253
+ const js = inject ? await inject(stringifiedCode, args.path) : `import injectStyle from '__inject-style';injectStyle(${stringifiedCode})`;
254
+ return {
255
+ contents: js,
256
+ loader: "js"
257
+ };
258
+ });
259
+ }
260
+ }
261
+ };
262
+ }
263
+ export {
264
+ shims,
265
+ injectStyles,
266
+ exports,
267
+ copy
268
+ };
package/package.json CHANGED
@@ -1,93 +1,102 @@
1
1
  {
2
- "name": "bunup",
3
- "description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
4
- "version": "0.8.42",
5
- "type": "module",
6
- "files": ["dist"],
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "import": "./dist/index.js",
12
- "types": "./dist/index.d.ts"
13
- },
14
- "./plugins": {
15
- "import": "./dist/plugins/index.js",
16
- "types": "./dist/plugins/index.d.ts"
17
- },
18
- "./cli": {
19
- "import": "./dist/cli/index.js"
20
- }
21
- },
22
- "license": "MIT",
23
- "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
24
- "maintainers": [
25
- {
26
- "name": "Arshad Yaseen",
27
- "email": "m@arshadyaseen.com",
28
- "url": "https://arshadyaseen.com"
29
- }
30
- ],
31
- "repository": {
32
- "type": "git",
33
- "url": "git+https://github.com/arshad-yaseen/bunup.git"
34
- },
35
- "funding": "https://github.com/sponsors/arshad-yaseen",
36
- "homepage": "https://bunup.dev",
37
- "keywords": ["bun", "bunup", "bun-bundler"],
38
- "bin": {
39
- "bunup": "dist/cli/index.js"
40
- },
41
- "dependencies": {
42
- "@clack/prompts": "^0.10.1",
43
- "bun-dts": "^0.1.70",
44
- "chokidar": "^4.0.3",
45
- "coffi": "^0.1.31",
46
- "giget": "^2.0.0",
47
- "picocolors": "^1.1.1",
48
- "replace-in-file": "^8.3.0",
49
- "tinyexec": "^1.0.1"
50
- },
51
- "devDependencies": {
52
- "@biomejs/biome": "^1.9.4",
53
- "@types/bun": "^1.2.5",
54
- "bumpp": "^10.1.0",
55
- "husky": "^9.1.7",
56
- "lightningcss": "^1.30.1",
57
- "lint-staged": "^15.5.1",
58
- "typescript": "^5.8.3"
59
- },
60
- "peerDependencies": {
61
- "typescript": ">=4.5.0",
62
- "lightningcss": ">=1.17.0"
63
- },
64
- "peerDependenciesMeta": {
65
- "typescript": {
66
- "optional": true
67
- },
68
- "lightningcss": {
69
- "optional": true
70
- }
71
- },
72
- "scripts": {
73
- "build": "bunx bunup@latest",
74
- "build:docs": "bun run --cwd docs build",
75
- "dev": "bunx bunup@latest --watch",
76
- "dev:docs": "bun run --cwd docs dev",
77
- "format": "biome format .",
78
- "format:fix": "biome format --write .",
79
- "lint": "biome check .",
80
- "lint:fix": "biome check --write .",
81
- "prepare": "husky",
82
- "test": "bun test",
83
- "test-build": "bun run --cwd tests build",
84
- "tsc": "tsc --noEmit",
85
- "publish:ci": "bun publish --access public --no-git-checks",
86
- "release": "bumpp"
87
- },
88
- "lint-staged": {
89
- "*": "bun run format:fix && git add .",
90
- "src/**/*.(m|c)?(j|t)s": "bun run tsc"
91
- },
92
- "workspaces": ["docs", "tests"]
93
- }
2
+ "name": "bunup",
3
+ "description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
4
+ "version": "0.8.44",
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ },
16
+ "./plugins": {
17
+ "import": "./dist/plugins.js",
18
+ "types": "./dist/plugins.d.ts"
19
+ },
20
+ "./cli": {
21
+ "import": "./dist/cli/index.js"
22
+ }
23
+ },
24
+ "license": "MIT",
25
+ "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
26
+ "maintainers": [
27
+ {
28
+ "name": "Arshad Yaseen",
29
+ "email": "m@arshadyaseen.com",
30
+ "url": "https://arshadyaseen.com"
31
+ }
32
+ ],
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/arshad-yaseen/bunup.git"
36
+ },
37
+ "funding": "https://github.com/sponsors/arshad-yaseen",
38
+ "homepage": "https://bunup.dev",
39
+ "keywords": [
40
+ "bun",
41
+ "bunup",
42
+ "bun-bundler"
43
+ ],
44
+ "bin": {
45
+ "bunup": "dist/cli/index.js"
46
+ },
47
+ "dependencies": {
48
+ "@clack/prompts": "^0.10.1",
49
+ "bun-dts": "^0.1.70",
50
+ "chokidar": "^4.0.3",
51
+ "coffi": "^0.1.31",
52
+ "giget": "^2.0.0",
53
+ "picocolors": "^1.1.1",
54
+ "replace-in-file": "^8.3.0",
55
+ "tinyexec": "^1.0.1"
56
+ },
57
+ "devDependencies": {
58
+ "@biomejs/biome": "^1.9.4",
59
+ "@types/bun": "^1.2.5",
60
+ "bumpp": "^10.1.0",
61
+ "husky": "^9.1.7",
62
+ "lightningcss": "^1.30.1",
63
+ "lint-staged": "^15.5.1",
64
+ "typescript": "^5.8.3"
65
+ },
66
+ "peerDependencies": {
67
+ "typescript": ">=4.5.0",
68
+ "lightningcss": ">=1.17.0"
69
+ },
70
+ "peerDependenciesMeta": {
71
+ "typescript": {
72
+ "optional": true
73
+ },
74
+ "lightningcss": {
75
+ "optional": true
76
+ }
77
+ },
78
+ "scripts": {
79
+ "build": "bunx bunup@latest",
80
+ "build:docs": "bun run --cwd docs build",
81
+ "dev": "bunx bunup@latest --watch",
82
+ "dev:docs": "bun run --cwd docs dev",
83
+ "format": "biome format .",
84
+ "format:fix": "biome format --write .",
85
+ "lint": "biome check .",
86
+ "lint:fix": "biome check --write .",
87
+ "prepare": "husky",
88
+ "test": "bun test",
89
+ "test-build": "bun run --cwd tests build",
90
+ "tsc": "tsc --noEmit",
91
+ "publish:ci": "bun publish --access public --no-git-checks",
92
+ "release": "bumpp"
93
+ },
94
+ "lint-staged": {
95
+ "*": "bun run format:fix && git add .",
96
+ "src/**/*.(m|c)?(j|t)s": "bun run tsc"
97
+ },
98
+ "workspaces": [
99
+ "docs",
100
+ "tests"
101
+ ]
102
+ }