Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit a668aa7

Browse files
committed
external
1 parent adf7c0a commit a668aa7

File tree

7 files changed

+119
-3
lines changed

7 files changed

+119
-3
lines changed

__fixtures__/imports/src/farewell.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as yolo from 'otherpackage';
2+
3+
export function farewell(name: string): string {
4+
myname();
5+
console.log(yolo);
6+
return `Goodbye, ${name}!`;
7+
}
8+
9+
function myname() {
10+
console.log('hello');
11+
}

__fixtures__/imports/src/greet.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as yolo from '~somepackage';
2+
3+
export function greet(name: string): string {
4+
console.log(yolo);
5+
return `Hello, ${name}!`;
6+
}

__fixtures__/imports/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { greet } from './greet';
2+
import { farewell } from './farewell';
3+
4+
function myname() {
5+
console.log('hello');
6+
}
7+
8+
console.log(greet('World'));
9+
console.log(farewell('World'));
10+
myname();

__output__/imports/bundle.js

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__output__/imports/bundle.js.map

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import fs from 'fs/promises';
2+
import { join, resolve } from 'path';
3+
4+
import { InterwebBuild, InterwebBuildOptions } from '../src/index';
5+
6+
const fixtureDir = resolve(join(__dirname, '/../../../__fixtures__/', 'imports'));
7+
const outputDir = resolve(join(__dirname, '/../../../__output__/', 'imports'));
8+
9+
describe('InterwebBuild', () => {
10+
it('builds the fixture project successfully', async () => {
11+
const outfile = join(outputDir, 'bundle.js');
12+
13+
const options: Partial<InterwebBuildOptions> = {
14+
entryPoints: [join(fixtureDir, 'src/index.ts')],
15+
outfile,
16+
external: ['otherpackage', '~somepackage']
17+
};
18+
19+
await InterwebBuild.build(options);
20+
21+
// Check if the output file exists
22+
const outfileExists = await fs.access(outfile)
23+
.then(() => true)
24+
.catch(() => false);
25+
26+
expect(outfileExists).toBe(true);
27+
28+
// Optionally, you can read the contents of the file and perform additional checks
29+
const bundleContent = await fs.readFile(outfile, 'utf-8');
30+
expect(bundleContent).toContain('function greet');
31+
expect(bundleContent).toContain('function farewell');
32+
});
33+
});

packages/build/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ export interface InterwebBuildOptions extends esbuild.BuildOptions {
66
}
77

88
export const defaultOptions: InterwebBuildOptions = {
9-
// entryPoints: ['src/index.ts'],
109
bundle: true,
1110
minify: false,
1211
outfile: 'dist/bundle.js',
1312
platform: 'node',
1413
sourcemap: true,
1514
target: 'ESNext',
16-
logLevel: 'info',
15+
logLevel: 'info'
1716
};
1817

1918
export const InterwebBuild = {
@@ -24,7 +23,7 @@ export const InterwebBuild = {
2423
if (mergedOptions.customPlugins) {
2524
mergedOptions.plugins = [
2625
...(mergedOptions.plugins || []),
27-
...mergedOptions.customPlugins,
26+
...mergedOptions.customPlugins
2827
];
2928
delete mergedOptions.customPlugins;
3029
}

0 commit comments

Comments
 (0)