forked from rollup/rollup
/
_config.js
156 lines (154 loc) · 4.56 KB
/
_config.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const path = require('path');
const assert = require('assert');
const ID_MAIN = path.join(__dirname, 'main.js');
const ID_LIB = path.join(__dirname, 'lib.js');
const ID_DEP = path.join(__dirname, 'dep.js');
module.exports = {
description: 'makes sure actual entry points are never implicit dependencies',
options: {
input: ['main', 'dep'],
preserveEntrySignatures: 'allow-extension',
plugins: {
name: 'test-plugin',
buildStart() {
this.emitFile({
type: 'chunk',
id: 'dep.js',
implicitlyLoadedAfterOneOf: [ID_MAIN]
});
},
buildEnd() {
assert.deepStrictEqual(JSON.parse(JSON.stringify(this.getModuleInfo(ID_MAIN))), {
ast: {
type: 'Program',
start: 0,
end: 51,
body: [
{
type: 'ImportDeclaration',
start: 0,
end: 30,
specifiers: [
{
type: 'ImportSpecifier',
start: 9,
end: 14,
imported: { type: 'Identifier', start: 9, end: 14, name: 'value' },
local: { type: 'Identifier', start: 9, end: 14, name: 'value' }
}
],
source: { type: 'Literal', start: 22, end: 29, value: './lib', raw: "'./lib'" }
},
{
type: 'ExpressionStatement',
start: 31,
end: 50,
expression: {
type: 'CallExpression',
start: 31,
end: 49,
callee: {
type: 'MemberExpression',
start: 31,
end: 42,
object: { type: 'Identifier', start: 31, end: 38, name: 'console' },
property: { type: 'Identifier', start: 39, end: 42, name: 'log' },
computed: false,
optional: false
},
arguments: [{ type: 'Identifier', start: 43, end: 48, name: 'value' }],
optional: false
}
}
],
sourceType: 'module'
},
code: "import { value } from './lib';\nconsole.log(value);\n",
dynamicallyImportedIds: [],
dynamicImporters: [],
hasModuleSideEffects: true,
id: ID_MAIN,
implicitlyLoadedAfterOneOf: [],
implicitlyLoadedBefore: [],
importedIds: [ID_LIB],
importers: [],
isEntry: true,
isExternal: false,
meta: {},
syntheticNamedExports: false
});
assert.deepStrictEqual(JSON.parse(JSON.stringify(this.getModuleInfo(ID_DEP))), {
ast: {
type: 'Program',
start: 0,
end: 51,
body: [
{
type: 'ImportDeclaration',
start: 0,
end: 30,
specifiers: [
{
type: 'ImportSpecifier',
start: 9,
end: 14,
imported: { type: 'Identifier', start: 9, end: 14, name: 'value' },
local: { type: 'Identifier', start: 9, end: 14, name: 'value' }
}
],
source: { type: 'Literal', start: 22, end: 29, value: './lib', raw: "'./lib'" }
},
{
type: 'ExpressionStatement',
start: 31,
end: 50,
expression: {
type: 'CallExpression',
start: 31,
end: 49,
callee: {
type: 'MemberExpression',
start: 31,
end: 42,
object: { type: 'Identifier', start: 31, end: 38, name: 'console' },
property: { type: 'Identifier', start: 39, end: 42, name: 'log' },
computed: false,
optional: false
},
arguments: [{ type: 'Identifier', start: 43, end: 48, name: 'value' }],
optional: false
}
}
],
sourceType: 'module'
},
code: "import { value } from './lib';\nconsole.log(value);\n",
dynamicallyImportedIds: [],
dynamicImporters: [],
hasModuleSideEffects: true,
id: ID_DEP,
implicitlyLoadedAfterOneOf: [],
implicitlyLoadedBefore: [],
importedIds: [ID_LIB],
importers: [],
isEntry: true,
isExternal: false,
meta: {},
syntheticNamedExports: false
});
},
generateBundle(options, bundle) {
const main = bundle['main.js'];
assert.deepStrictEqual(main.implicitlyLoadedBefore, [], 'main.implicitlyLoadedBefore');
assert.strictEqual(main.isEntry, true, 'main.isEntry');
assert.strictEqual(main.isDynamicEntry, false, 'main.isDynamicEntry');
assert.strictEqual(main.isImplicitEntry, false, 'main.isImplicitEntry');
const dep = bundle['dep.js'];
assert.deepStrictEqual(dep.implicitlyLoadedBefore, [], 'dep.implicitlyLoadedBefore');
assert.strictEqual(dep.isEntry, true, 'dep.isEntry');
assert.strictEqual(dep.isDynamicEntry, false, 'dep.isDynamicEntry');
assert.strictEqual(dep.isImplicitEntry, false, 'dep.isImplicitEntry');
}
}
}
};