@b9g/libuild 0.1.3 → 0.1.5
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 +11 -13
- package/package.json +15 -15
- package/src/cli.cjs +62 -795
- package/src/cli.js +167 -11
- package/src/libuild.cjs +344 -183
- package/src/libuild.d.ts +1 -1
- package/src/libuild.js +934 -8
- package/src/chunk-EVLPGECD.js +0 -71
- package/src/chunk-EVLPGECD.js.map +0 -7
- package/src/chunk-YRPHTAV4.js +0 -713
- package/src/chunk-YRPHTAV4.js.map +0 -7
- package/src/cli.cjs.map +0 -7
- package/src/cli.js.map +0 -7
- package/src/libuild.cjs.map +0 -7
- package/src/libuild.js.map +0 -7
- package/src/package-4E3XK74J.js +0 -132
- package/src/package-4E3XK74J.js.map +0 -7
- package/src/umd-plugin.cjs +0 -105
- package/src/umd-plugin.cjs.map +0 -7
- package/src/umd-plugin.d.ts +0 -8
- package/src/umd-plugin.js +0 -8
- package/src/umd-plugin.js.map +0 -7
package/src/umd-plugin.cjs
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/umd-plugin.ts
|
|
31
|
-
var umd_plugin_exports = {};
|
|
32
|
-
__export(umd_plugin_exports, {
|
|
33
|
-
umdPlugin: () => umdPlugin
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(umd_plugin_exports);
|
|
36
|
-
var FS = __toESM(require("fs/promises"), 1);
|
|
37
|
-
var Path = __toESM(require("path"), 1);
|
|
38
|
-
var import_magic_string = __toESM(require("magic-string"), 1);
|
|
39
|
-
function umdPlugin(options) {
|
|
40
|
-
return {
|
|
41
|
-
name: "umd-wrapper",
|
|
42
|
-
setup(build) {
|
|
43
|
-
build.onEnd(async (result) => {
|
|
44
|
-
if (result.errors.length > 0)
|
|
45
|
-
return;
|
|
46
|
-
const outputDir = build.initialOptions.outdir;
|
|
47
|
-
if (outputDir) {
|
|
48
|
-
const files = await FS.readdir(outputDir);
|
|
49
|
-
for (const file of files) {
|
|
50
|
-
if (file.endsWith(".js") && !file.endsWith(".js.map")) {
|
|
51
|
-
await wrapWithUmd(Path.join(outputDir, file), options.globalName);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
async function wrapWithUmd(filePath, globalName) {
|
|
60
|
-
const code = await FS.readFile(filePath, "utf-8");
|
|
61
|
-
const ms = new import_magic_string.default(code);
|
|
62
|
-
const sourcemapComment = code.match(/\/\/# sourceMappingURL=.+$/m);
|
|
63
|
-
if (sourcemapComment) {
|
|
64
|
-
const index = code.lastIndexOf(sourcemapComment[0]);
|
|
65
|
-
ms.remove(index, index + sourcemapComment[0].length);
|
|
66
|
-
}
|
|
67
|
-
const exportsMatch = code.match(/\nmodule\.exports\s*=\s*([^;]+);?\s*$/);
|
|
68
|
-
if (exportsMatch) {
|
|
69
|
-
const index = code.lastIndexOf(exportsMatch[0]);
|
|
70
|
-
ms.overwrite(index, index + exportsMatch[0].length, `
|
|
71
|
-
return ${exportsMatch[1]};`);
|
|
72
|
-
}
|
|
73
|
-
const umdHeader = `(function (root, factory) {
|
|
74
|
-
if (typeof define === 'function' && define.amd) {
|
|
75
|
-
// AMD
|
|
76
|
-
define([], factory);
|
|
77
|
-
} else if (typeof module === 'object' && module.exports) {
|
|
78
|
-
// CommonJS
|
|
79
|
-
module.exports = factory();
|
|
80
|
-
} else {
|
|
81
|
-
// Browser globals
|
|
82
|
-
root.${globalName} = factory();
|
|
83
|
-
}
|
|
84
|
-
}(typeof self !== 'undefined' ? self : this, function () {
|
|
85
|
-
`;
|
|
86
|
-
const umdFooter = `
|
|
87
|
-
}));`;
|
|
88
|
-
ms.prepend(umdHeader);
|
|
89
|
-
ms.append(umdFooter);
|
|
90
|
-
const result = ms.toString();
|
|
91
|
-
const map = ms.generateMap({
|
|
92
|
-
file: Path.basename(filePath),
|
|
93
|
-
source: Path.basename(filePath).replace(".js", ".ts"),
|
|
94
|
-
includeContent: true
|
|
95
|
-
});
|
|
96
|
-
await FS.writeFile(filePath, result);
|
|
97
|
-
await FS.writeFile(filePath + ".map", map.toString());
|
|
98
|
-
await FS.writeFile(filePath, result + `
|
|
99
|
-
//# sourceMappingURL=${Path.basename(filePath)}.map`);
|
|
100
|
-
}
|
|
101
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
-
0 && (module.exports = {
|
|
103
|
-
umdPlugin
|
|
104
|
-
});
|
|
105
|
-
//# sourceMappingURL=umd-plugin.cjs.map
|
package/src/umd-plugin.cjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/umd-plugin.ts"],
|
|
4
|
-
"sourcesContent": ["import * as FS from \"fs/promises\";\nimport * as Path from \"path\";\nimport MagicString from \"magic-string\";\n\ninterface UmdPluginOptions {\n globalName: string;\n}\n\nexport function umdPlugin(options: UmdPluginOptions) {\n return {\n name: \"umd-wrapper\",\n setup(build: any) {\n build.onEnd(async (result: any) => {\n if (result.errors.length > 0) return;\n\n // ESBuild doesn't provide outputFiles by default unless write: false\n // We need to find the generated files in the output directory\n const outputDir = build.initialOptions.outdir;\n if (outputDir) {\n const files = await FS.readdir(outputDir);\n for (const file of files) {\n if (file.endsWith(\".js\") && !file.endsWith(\".js.map\")) {\n await wrapWithUmd(Path.join(outputDir, file), options.globalName);\n }\n }\n }\n });\n },\n };\n}\n\nasync function wrapWithUmd(filePath: string, globalName: string) {\n const code = await FS.readFile(filePath, \"utf-8\");\n const ms = new MagicString(code);\n\n // Remove sourcemap comment\n const sourcemapComment = code.match(/\\/\\/# sourceMappingURL=.+$/m);\n if (sourcemapComment) {\n const index = code.lastIndexOf(sourcemapComment[0]);\n ms.remove(index, index + sourcemapComment[0].length);\n }\n\n // Replace module.exports with return\n const exportsMatch = code.match(/\\nmodule\\.exports\\s*=\\s*([^;]+);?\\s*$/);\n if (exportsMatch) {\n const index = code.lastIndexOf(exportsMatch[0]);\n ms.overwrite(index, index + exportsMatch[0].length, `\\nreturn ${exportsMatch[1]};`);\n }\n\n // UMD wrapper\n const umdHeader = `(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD\n define([], factory);\n } else if (typeof module === 'object' && module.exports) {\n // CommonJS\n module.exports = factory();\n } else {\n // Browser globals\n root.${globalName} = factory();\n }\n}(typeof self !== 'undefined' ? self : this, function () {\n`;\n\n const umdFooter = `\n}));`;\n\n // Wrap with UMD\n ms.prepend(umdHeader);\n ms.append(umdFooter);\n\n // Generate sourcemap and write files\n const result = ms.toString();\n const map = ms.generateMap({\n file: Path.basename(filePath),\n source: Path.basename(filePath).replace(\".js\", \".ts\"),\n includeContent: true,\n });\n\n await FS.writeFile(filePath, result);\n await FS.writeFile(filePath + \".map\", map.toString());\n await FS.writeFile(filePath, result + `\\n//# sourceMappingURL=${Path.basename(filePath)}.map`);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;AACtB,0BAAwB;AAMjB,SAAS,UAAU,SAA2B;AACnD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,OAAY;AAChB,YAAM,MAAM,OAAO,WAAgB;AACjC,YAAI,OAAO,OAAO,SAAS;AAAG;AAI9B,cAAM,YAAY,MAAM,eAAe;AACvC,YAAI,WAAW;AACb,gBAAM,QAAQ,MAAS,WAAQ,SAAS;AACxC,qBAAW,QAAQ,OAAO;AACxB,gBAAI,KAAK,SAAS,KAAK,KAAK,CAAC,KAAK,SAAS,SAAS,GAAG;AACrD,oBAAM,YAAiB,UAAK,WAAW,IAAI,GAAG,QAAQ,UAAU;AAAA,YAClE;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,eAAe,YAAY,UAAkB,YAAoB;AAC/D,QAAM,OAAO,MAAS,YAAS,UAAU,OAAO;AAChD,QAAM,KAAK,IAAI,oBAAAA,QAAY,IAAI;AAG/B,QAAM,mBAAmB,KAAK,MAAM,6BAA6B;AACjE,MAAI,kBAAkB;AACpB,UAAM,QAAQ,KAAK,YAAY,iBAAiB,CAAC,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