@overlayed/cli 0.0.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.
- package/.attest/assertions/typescript.json +1 -0
- package/LICENSE.md +16 -0
- package/README.md +3 -0
- package/__mocks__/fs/promises.cjs +2 -0
- package/__mocks__/fs.cjs +2 -0
- package/__tests__/bundler.test.ts +457 -0
- package/__tests__/temp.test.ts +7 -0
- package/__tests__/utils.ts +2 -0
- package/dist/chunk-RDQt0V5E.js +31 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1682 -0
- package/dist/lib-DalWKwNu.js +1041 -0
- package/moon.yml +18 -0
- package/package.json +38 -0
- package/setupVitest.ts +5 -0
- package/src/bundle/command.ts +87 -0
- package/src/bundle/internal/appBundler.ts +35 -0
- package/src/bundle/internal/bundler.ts +77 -0
- package/src/bundle/internal/isBundleConfig.ts +6 -0
- package/src/cli.ts +4 -0
- package/src/consts.ts +3 -0
- package/temp/myfile.txt +0 -0
- package/temp/overlayed.config.ts +8 -0
- package/temp/someotherfile.ts +0 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +38 -0
- package/tsdown.config.ts +13 -0
- package/vitest.config.ts +17 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present OVERLAYED LLC. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software and associated documentation files (the "Software") are the proprietary and confidential information of
|
|
6
|
+
OVERLAYED LLC. You may not use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software
|
|
7
|
+
without explicit written permission from OVERLAYED LLC.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
10
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
11
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
12
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
13
|
+
|
|
14
|
+
Unauthorized copying, transfer, or reproduction of the contents of this Software, via any medium is strictly prohibited.
|
|
15
|
+
|
|
16
|
+
All rights not expressly granted herein are reserved by OVERLAYED LLC.
|
package/README.md
ADDED
package/__mocks__/fs.cjs
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { describe, beforeEach, afterEach, it, expect, vi, type MockedFunction } from "vitest";
|
|
2
|
+
import { vol } from "memfs";
|
|
3
|
+
import { Bundler } from "../src/bundle/internal/bundler";
|
|
4
|
+
import { AppBundler } from "../src/bundle/internal/appBundler";
|
|
5
|
+
import { glob } from "glob";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
vi.mock("node:fs");
|
|
9
|
+
vi.mock("glob");
|
|
10
|
+
|
|
11
|
+
const mockGlob = glob as MockedFunction<typeof glob>;
|
|
12
|
+
|
|
13
|
+
describe("Bundler", () => {
|
|
14
|
+
let bundler: Bundler;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
vol.reset();
|
|
18
|
+
bundler = new Bundler();
|
|
19
|
+
vi.clearAllMocks();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
vi.clearAllMocks();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("addGlobPattern", () => {
|
|
27
|
+
it("should add a single string pattern", () => {
|
|
28
|
+
bundler.addGlobPattern("*.js");
|
|
29
|
+
// Test passes if no error is thrown
|
|
30
|
+
expect(bundler).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should add an array of patterns", () => {
|
|
34
|
+
bundler.addGlobPattern(["*.js", "*.ts"]);
|
|
35
|
+
// Test passes if no error is thrown
|
|
36
|
+
expect(bundler).toBeDefined();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should add pattern with options", () => {
|
|
40
|
+
bundler.addGlobPattern("*.js", { ignore: ["node_modules/**"] });
|
|
41
|
+
// Test passes if no error is thrown
|
|
42
|
+
expect(bundler).toBeDefined();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should add multiple patterns", () => {
|
|
46
|
+
bundler.addGlobPattern("*.js");
|
|
47
|
+
bundler.addGlobPattern(["*.ts", "*.json"]);
|
|
48
|
+
bundler.addGlobPattern("*.md", { ignore: ["README.md"] });
|
|
49
|
+
// Test passes if no error is thrown
|
|
50
|
+
expect(bundler).toBeDefined();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("bundle", () => {
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
// Set up a mock file system with current working directory paths
|
|
57
|
+
const testCwd = process.cwd();
|
|
58
|
+
vol.fromJSON({
|
|
59
|
+
[path.join(testCwd, "file1.js")]: "console.log('file1');",
|
|
60
|
+
[path.join(testCwd, "file2.js")]: "console.log('file2');",
|
|
61
|
+
[path.join(testCwd, "src", "index.ts")]: "export const hello = 'world';",
|
|
62
|
+
[path.join(testCwd, "src", "utils.ts")]: "export const utils = true;",
|
|
63
|
+
[path.join(testCwd, "package.json")]: '{"name": "test-project"}',
|
|
64
|
+
[path.join(testCwd, "README.md")]: "# Test Project",
|
|
65
|
+
[path.join(testCwd, "node_modules", "dep", "index.js")]: "module.exports = {};",
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should bundle files matching a single pattern", async () => {
|
|
70
|
+
const testCwd = process.cwd();
|
|
71
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "file1.js"), path.join(testCwd, "file2.js")]);
|
|
72
|
+
|
|
73
|
+
bundler.addGlobPattern("*.js");
|
|
74
|
+
const zip = await bundler.bundle();
|
|
75
|
+
|
|
76
|
+
expect(mockGlob).toHaveBeenCalledWith(
|
|
77
|
+
["*.js"],
|
|
78
|
+
expect.objectContaining({
|
|
79
|
+
absolute: true,
|
|
80
|
+
cwd: testCwd,
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const files = Object.keys(zip.files);
|
|
85
|
+
expect(files).toContain("file1.js");
|
|
86
|
+
expect(files).toContain("file2.js");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("should bundle files matching multiple patterns", async () => {
|
|
90
|
+
const testCwd = process.cwd();
|
|
91
|
+
mockGlob
|
|
92
|
+
.mockResolvedValueOnce([path.join(testCwd, "file1.js"), path.join(testCwd, "file2.js")])
|
|
93
|
+
.mockResolvedValueOnce([path.join(testCwd, "src", "index.ts"), path.join(testCwd, "src", "utils.ts")]);
|
|
94
|
+
|
|
95
|
+
bundler.addGlobPattern("*.js");
|
|
96
|
+
bundler.addGlobPattern("src/*.ts");
|
|
97
|
+
const zip = await bundler.bundle();
|
|
98
|
+
|
|
99
|
+
expect(mockGlob).toHaveBeenCalledTimes(2);
|
|
100
|
+
expect(mockGlob).toHaveBeenNthCalledWith(1, ["*.js"], expect.any(Object));
|
|
101
|
+
expect(mockGlob).toHaveBeenNthCalledWith(2, ["src/*.ts"], expect.any(Object));
|
|
102
|
+
|
|
103
|
+
const files = Object.keys(zip.files);
|
|
104
|
+
expect(files).toContain("file1.js");
|
|
105
|
+
expect(files).toContain("file2.js");
|
|
106
|
+
expect(files).toContain(path.join("src", "index.ts"));
|
|
107
|
+
expect(files).toContain(path.join("src", "utils.ts"));
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should handle array patterns", async () => {
|
|
111
|
+
const testCwd = process.cwd();
|
|
112
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "file1.js"), path.join(testCwd, "src", "index.ts")]);
|
|
113
|
+
|
|
114
|
+
bundler.addGlobPattern(["*.js", "src/*.ts"]);
|
|
115
|
+
const zip = await bundler.bundle();
|
|
116
|
+
|
|
117
|
+
expect(mockGlob).toHaveBeenCalledWith(["*.js", "src/*.ts"], expect.any(Object));
|
|
118
|
+
|
|
119
|
+
const files = Object.keys(zip.files);
|
|
120
|
+
expect(files).toContain("file1.js");
|
|
121
|
+
expect(files).toContain(path.join("src", "index.ts"));
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should respect glob options", async () => {
|
|
125
|
+
const testCwd = process.cwd();
|
|
126
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "file1.js")]);
|
|
127
|
+
|
|
128
|
+
const options = { ignore: ["node_modules/**"] };
|
|
129
|
+
bundler.addGlobPattern("**/*.js", options);
|
|
130
|
+
await bundler.bundle();
|
|
131
|
+
|
|
132
|
+
expect(mockGlob).toHaveBeenCalledWith(
|
|
133
|
+
["**/*.js"],
|
|
134
|
+
expect.objectContaining({
|
|
135
|
+
ignore: ["node_modules/**"],
|
|
136
|
+
absolute: true,
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("should use provided cwd option", async () => {
|
|
142
|
+
const customCwd = path.resolve("custom", "path");
|
|
143
|
+
mockGlob.mockResolvedValueOnce([path.join(customCwd, "file.js")]);
|
|
144
|
+
|
|
145
|
+
bundler.addGlobPattern("*.js", { cwd: customCwd });
|
|
146
|
+
await bundler.bundle();
|
|
147
|
+
|
|
148
|
+
expect(mockGlob).toHaveBeenCalledWith(
|
|
149
|
+
["*.js"],
|
|
150
|
+
expect.objectContaining({
|
|
151
|
+
cwd: customCwd,
|
|
152
|
+
absolute: true,
|
|
153
|
+
}),
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("should handle URL cwd option", async () => {
|
|
158
|
+
const testCwd = path.resolve("url", "path");
|
|
159
|
+
// Create the directory structure in the mock filesystem
|
|
160
|
+
vol.mkdirSync(testCwd, { recursive: true });
|
|
161
|
+
vol.writeFileSync(path.join(testCwd, "file.js"), "test");
|
|
162
|
+
|
|
163
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "file.js")]);
|
|
164
|
+
|
|
165
|
+
const urlCwd = new URL(`file:///${testCwd.replace(/\\/g, "/")}`);
|
|
166
|
+
bundler.addGlobPattern("*.js", { cwd: urlCwd });
|
|
167
|
+
await bundler.bundle();
|
|
168
|
+
|
|
169
|
+
expect(mockGlob).toHaveBeenCalledWith(
|
|
170
|
+
["*.js"],
|
|
171
|
+
expect.objectContaining({
|
|
172
|
+
cwd: testCwd,
|
|
173
|
+
absolute: true,
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("should resolve relative cwd paths", async () => {
|
|
179
|
+
mockGlob.mockResolvedValueOnce([]);
|
|
180
|
+
|
|
181
|
+
bundler.addGlobPattern("*.js", { cwd: "./relative/path" });
|
|
182
|
+
await bundler.bundle();
|
|
183
|
+
|
|
184
|
+
expect(mockGlob).toHaveBeenCalledWith(
|
|
185
|
+
["*.js"],
|
|
186
|
+
expect.objectContaining({
|
|
187
|
+
cwd: path.resolve("./relative/path"),
|
|
188
|
+
absolute: true,
|
|
189
|
+
}),
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("should create zip with correct file paths relative to cwd", async () => {
|
|
194
|
+
const testCwd = path.resolve("project");
|
|
195
|
+
vol.mkdirSync(path.join(testCwd, "src"), { recursive: true });
|
|
196
|
+
vol.writeFileSync(path.join(testCwd, "src", "index.ts"), "test content");
|
|
197
|
+
vol.writeFileSync(path.join(testCwd, "package.json"), "{}");
|
|
198
|
+
|
|
199
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.ts"), path.join(testCwd, "package.json")]);
|
|
200
|
+
|
|
201
|
+
bundler.addGlobPattern("**/*", { cwd: testCwd });
|
|
202
|
+
const zip = await bundler.bundle();
|
|
203
|
+
|
|
204
|
+
const files = Object.keys(zip.files);
|
|
205
|
+
expect(files).toContain(path.join("src", "index.ts"));
|
|
206
|
+
expect(files).toContain("package.json");
|
|
207
|
+
// Ensure absolute paths are not used
|
|
208
|
+
expect(files.every((f) => !path.isAbsolute(f))).toBe(true);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("should handle empty glob results", async () => {
|
|
212
|
+
mockGlob.mockResolvedValueOnce([]);
|
|
213
|
+
|
|
214
|
+
bundler.addGlobPattern("*.nonexistent");
|
|
215
|
+
const zip = await bundler.bundle();
|
|
216
|
+
|
|
217
|
+
expect(Object.keys(zip.files)).toHaveLength(0);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("should handle multiple patterns with some empty results", async () => {
|
|
221
|
+
const testCwd = process.cwd();
|
|
222
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "file1.js")]).mockResolvedValueOnce([]);
|
|
223
|
+
|
|
224
|
+
bundler.addGlobPattern("*.js");
|
|
225
|
+
bundler.addGlobPattern("*.nonexistent");
|
|
226
|
+
const zip = await bundler.bundle();
|
|
227
|
+
|
|
228
|
+
const files = Object.keys(zip.files);
|
|
229
|
+
expect(files).toContain("file1.js");
|
|
230
|
+
expect(files).toHaveLength(1);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("should use DEFLATE compression", async () => {
|
|
234
|
+
const testCwd = process.cwd();
|
|
235
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "file1.js")]);
|
|
236
|
+
|
|
237
|
+
bundler.addGlobPattern("*.js");
|
|
238
|
+
const zip = await bundler.bundle();
|
|
239
|
+
|
|
240
|
+
const files = Object.keys(zip.files);
|
|
241
|
+
expect(files).toHaveLength(1);
|
|
242
|
+
|
|
243
|
+
const file = zip.files[files[0]];
|
|
244
|
+
expect(file).toBeDefined();
|
|
245
|
+
expect(file.options.compression).toBe("DEFLATE");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("should handle glob errors gracefully", async () => {
|
|
249
|
+
const error = new Error("Glob failed");
|
|
250
|
+
mockGlob.mockRejectedValueOnce(error);
|
|
251
|
+
|
|
252
|
+
bundler.addGlobPattern("*.js");
|
|
253
|
+
|
|
254
|
+
await expect(bundler.bundle()).rejects.toThrow("Glob failed");
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe("AppBundler", () => {
|
|
259
|
+
let appBundler: AppBundler;
|
|
260
|
+
|
|
261
|
+
beforeEach(() => {
|
|
262
|
+
vol.reset();
|
|
263
|
+
appBundler = new AppBundler();
|
|
264
|
+
vi.clearAllMocks();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
describe("constructor", () => {
|
|
268
|
+
it("should automatically include package.json pattern", () => {
|
|
269
|
+
// Test passes if no error is thrown during construction
|
|
270
|
+
// The package.json pattern is added in constructor
|
|
271
|
+
expect(appBundler).toBeDefined();
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
describe("installer folder exclusion", () => {
|
|
276
|
+
beforeEach(() => {
|
|
277
|
+
const testCwd = process.cwd();
|
|
278
|
+
vol.fromJSON({
|
|
279
|
+
[path.join(testCwd, "package.json")]: '{"name": "test-app"}',
|
|
280
|
+
[path.join(testCwd, "src", "index.js")]: "console.log('app');",
|
|
281
|
+
[path.join(testCwd, "installer", "setup.exe")]: "binary content",
|
|
282
|
+
[path.join(testCwd, "installer", "data", "config.json")]: '{"setup": true}',
|
|
283
|
+
[path.join(testCwd, "nested", "installer", "tool.exe")]: "tool content",
|
|
284
|
+
[path.join(testCwd, "dist", "app.js")]: "built app",
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("should exclude installer folder when no ignore options provided", async () => {
|
|
289
|
+
const testCwd = process.cwd();
|
|
290
|
+
// Mock package.json call (first call for auto-added pattern)
|
|
291
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
|
|
292
|
+
// Mock user pattern call
|
|
293
|
+
mockGlob.mockResolvedValueOnce([
|
|
294
|
+
path.join(testCwd, "src", "index.js"),
|
|
295
|
+
path.join(testCwd, "dist", "app.js"),
|
|
296
|
+
]);
|
|
297
|
+
|
|
298
|
+
appBundler.addGlobPattern("**/*.js");
|
|
299
|
+
const zip = await appBundler.bundle();
|
|
300
|
+
|
|
301
|
+
expect(mockGlob).toHaveBeenNthCalledWith(
|
|
302
|
+
2,
|
|
303
|
+
["**/*.js"],
|
|
304
|
+
expect.objectContaining({
|
|
305
|
+
ignore: "**/installer/**",
|
|
306
|
+
}),
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const files = Object.keys(zip.files);
|
|
310
|
+
expect(files).toContain("package.json");
|
|
311
|
+
expect(files).toContain(path.join("src", "index.js"));
|
|
312
|
+
expect(files).toContain(path.join("dist", "app.js"));
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("should merge installer exclusion with existing ignore patterns (string)", async () => {
|
|
316
|
+
const testCwd = process.cwd();
|
|
317
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
|
|
318
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.js")]);
|
|
319
|
+
|
|
320
|
+
appBundler.addGlobPattern("**/*.js", { ignore: "node_modules/**" });
|
|
321
|
+
await appBundler.bundle();
|
|
322
|
+
|
|
323
|
+
expect(mockGlob).toHaveBeenNthCalledWith(
|
|
324
|
+
2,
|
|
325
|
+
["**/*.js"],
|
|
326
|
+
expect.objectContaining({
|
|
327
|
+
ignore: ["node_modules/**", "**/installer/**"],
|
|
328
|
+
}),
|
|
329
|
+
);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("should merge installer exclusion with existing ignore patterns (array)", async () => {
|
|
333
|
+
const testCwd = process.cwd();
|
|
334
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
|
|
335
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.js")]);
|
|
336
|
+
|
|
337
|
+
appBundler.addGlobPattern("**/*.js", {
|
|
338
|
+
ignore: ["node_modules/**", "*.test.js"],
|
|
339
|
+
});
|
|
340
|
+
await appBundler.bundle();
|
|
341
|
+
|
|
342
|
+
expect(mockGlob).toHaveBeenNthCalledWith(
|
|
343
|
+
2,
|
|
344
|
+
["**/*.js"],
|
|
345
|
+
expect.objectContaining({
|
|
346
|
+
ignore: ["node_modules/**", "*.test.js", "**/installer/**"],
|
|
347
|
+
}),
|
|
348
|
+
);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("should not duplicate installer exclusion if already present", async () => {
|
|
352
|
+
const testCwd = process.cwd();
|
|
353
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
|
|
354
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.js")]);
|
|
355
|
+
|
|
356
|
+
appBundler.addGlobPattern("**/*.js", {
|
|
357
|
+
ignore: ["**/installer/**", "node_modules/**"],
|
|
358
|
+
});
|
|
359
|
+
await appBundler.bundle();
|
|
360
|
+
|
|
361
|
+
expect(mockGlob).toHaveBeenNthCalledWith(
|
|
362
|
+
2,
|
|
363
|
+
["**/*.js"],
|
|
364
|
+
expect.objectContaining({
|
|
365
|
+
ignore: ["**/installer/**", "node_modules/**", "**/installer/**"],
|
|
366
|
+
}),
|
|
367
|
+
);
|
|
368
|
+
// Note: The current implementation doesn't dedupe, which is acceptable
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
describe("package.json requirement", () => {
|
|
373
|
+
it("should include package.json by default", async () => {
|
|
374
|
+
const testCwd = process.cwd();
|
|
375
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
|
|
376
|
+
|
|
377
|
+
const zip = await appBundler.bundle();
|
|
378
|
+
|
|
379
|
+
expect(mockGlob).toHaveBeenCalledWith(["package.json"], expect.any(Object));
|
|
380
|
+
|
|
381
|
+
const files = Object.keys(zip.files);
|
|
382
|
+
expect(files).toContain("package.json");
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("should not throw error when package.json is automatically included", async () => {
|
|
386
|
+
const testCwd = process.cwd();
|
|
387
|
+
// Set up files in mock filesystem first
|
|
388
|
+
vol.fromJSON({
|
|
389
|
+
[path.join(testCwd, "package.json")]: '{"name": "test"}',
|
|
390
|
+
[path.join(testCwd, "src", "index.js")]: "console.log('test');",
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
|
|
394
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.js")]);
|
|
395
|
+
|
|
396
|
+
appBundler.addGlobPattern("src/**/*.js");
|
|
397
|
+
|
|
398
|
+
await expect(appBundler.bundle()).resolves.toBeDefined();
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it("should throw error if package.json is not found despite being added", async () => {
|
|
402
|
+
// Mock package.json pattern to return empty (simulating missing file)
|
|
403
|
+
mockGlob.mockResolvedValueOnce([]);
|
|
404
|
+
mockGlob.mockResolvedValueOnce([]);
|
|
405
|
+
|
|
406
|
+
appBundler.addGlobPattern("src/**/*.js");
|
|
407
|
+
|
|
408
|
+
await expect(appBundler.bundle()).rejects.toThrow("package.json not found");
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
describe("multiple patterns with installer exclusion", () => {
|
|
413
|
+
beforeEach(() => {
|
|
414
|
+
const testCwd = process.cwd();
|
|
415
|
+
vol.fromJSON({
|
|
416
|
+
[path.join(testCwd, "package.json")]: '{"name": "test-app"}',
|
|
417
|
+
[path.join(testCwd, "src", "index.js")]: "app code",
|
|
418
|
+
[path.join(testCwd, "assets", "logo.png")]: "image data",
|
|
419
|
+
[path.join(testCwd, "installer", "setup.exe")]: "installer",
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it("should apply installer exclusion to all patterns", async () => {
|
|
424
|
+
const testCwd = process.cwd();
|
|
425
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
|
|
426
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.js")]);
|
|
427
|
+
mockGlob.mockResolvedValueOnce([path.join(testCwd, "assets", "logo.png")]);
|
|
428
|
+
|
|
429
|
+
appBundler.addGlobPattern("src/**/*.js", { ignore: "*.test.js" });
|
|
430
|
+
appBundler.addGlobPattern("assets/**/*");
|
|
431
|
+
|
|
432
|
+
const zip = await appBundler.bundle();
|
|
433
|
+
|
|
434
|
+
// Check that installer exclusion is applied to both patterns
|
|
435
|
+
expect(mockGlob).toHaveBeenNthCalledWith(
|
|
436
|
+
2,
|
|
437
|
+
["src/**/*.js"],
|
|
438
|
+
expect.objectContaining({
|
|
439
|
+
ignore: ["*.test.js", "**/installer/**"],
|
|
440
|
+
}),
|
|
441
|
+
);
|
|
442
|
+
expect(mockGlob).toHaveBeenNthCalledWith(
|
|
443
|
+
3,
|
|
444
|
+
["assets/**/*"],
|
|
445
|
+
expect.objectContaining({
|
|
446
|
+
ignore: "**/installer/**",
|
|
447
|
+
}),
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
const files = Object.keys(zip.files);
|
|
451
|
+
expect(files).toContain("package.json");
|
|
452
|
+
expect(files).toContain(path.join("src", "index.js"));
|
|
453
|
+
expect(files).toContain(path.join("assets", "logo.png"));
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __commonJS = (cb, mod) => function() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var __toDynamicImportESM = (isNodeMode) => (mod) => __toESM(mod.default, isNodeMode);
|
|
28
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { __commonJS, __require, __toDynamicImportESM };
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|