-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
api.js
109 lines (91 loc) 路 2.42 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// @flow strict-local
import path from 'path';
import assert from 'assert';
import {
distDir,
bundle,
assertBundles,
outputFS,
overlayFS,
fsFixture,
} from '@parcel/test-utils';
import {PARCEL_VERSION} from '../../core/src/constants';
describe('JS API', function () {
it('should respect distEntry', async function () {
const NAME = 'custom-name.js';
let b = await bundle(
path.join(__dirname, '/integration/js-comment/index.js'),
{
targets: {
default: {distDir, distEntry: NAME},
},
},
);
assertBundles(b, [
{
name: NAME,
type: 'js',
assets: ['index.js'],
},
]);
assert(await outputFS.exists(path.join(distDir, NAME)));
});
it('should run additional reports from the options', async function () {
let b = await bundle(
path.join(__dirname, '/integration/js-comment/index.js'),
{
additionalReporters: [
{
packageName: '@parcel/reporter-bundle-buddy',
resolveFrom: __dirname,
},
],
},
);
assertBundles(b, [
{
type: 'js',
assets: ['index.js'],
},
]);
assert(await outputFS.exists(path.join(distDir, 'bundle-buddy.json')));
});
describe('Reporter API', () => {
it('should pass the parcel version to plugins', async () => {
const dir = path.join(__dirname, 'plugin-parcel-version');
overlayFS.mkdirp(dir);
await fsFixture(overlayFS, dir)`
index.js:
export default 'Hi';
.parcelrc:
{
extends: "@parcel/config-default",
reporters: ["./reporter-plugin.js", "..."],
}
package.json:
{
"version": "1234"
}
yarn.lock:
reporter-plugin.js:
import {Reporter} from '@parcel/plugin';
import path from 'node:path';
export default new Reporter({
async report({event, options}) {
if (event.type === 'buildSuccess') {
await options.outputFS.writeFile(path.join(options.projectRoot, 'parcel-version.txt'), options.parcelVersion);
}
}
})
`;
await bundle(path.join(dir, 'index.js'), {
inputFS: overlayFS,
outputFS: overlayFS,
});
assert.equal(
await overlayFS.readFile(path.join(dir, 'parcel-version.txt')),
PARCEL_VERSION,
);
});
});
});