@polylith/builder 0.0.24 → 0.0.25
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/App.js +35 -11
- package/ConfigApp.js +2 -2
- package/ConfigFeature.js +4 -2
- package/Feature.js +2 -2
- package/index.js +3 -3
- package/package.json +1 -1
- package/plugin-loader.js +4 -7
package/App.js
CHANGED
|
@@ -12,7 +12,7 @@ import mainHTML from './plugin-main-html.js';
|
|
|
12
12
|
import features from './plugin-features.js';
|
|
13
13
|
import styles from "rollup-plugin-styles";
|
|
14
14
|
|
|
15
|
-
import ConfigFeature from './ConfigFeature';
|
|
15
|
+
import ConfigFeature from './ConfigFeature.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* call this function to check if the given file exists
|
|
@@ -33,7 +33,7 @@ async function fileExists(path) {
|
|
|
33
33
|
/**
|
|
34
34
|
* The base class for applications. Applications inherit from this class
|
|
35
35
|
*/
|
|
36
|
-
export class App {
|
|
36
|
+
export default class App {
|
|
37
37
|
/**
|
|
38
38
|
* Construct the app object.
|
|
39
39
|
*
|
|
@@ -47,7 +47,7 @@ export class App {
|
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
49
|
constructor(name, root, index , dest) {
|
|
50
|
-
root =
|
|
50
|
+
root = App.fixPath(root);
|
|
51
51
|
this.root = root;
|
|
52
52
|
|
|
53
53
|
var filename = path.posix.join(root, index);
|
|
@@ -64,7 +64,7 @@ export class App {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
static fileToPath(filename) {
|
|
67
|
-
filename =
|
|
67
|
+
filename = App.fixPath(filename);
|
|
68
68
|
return path.posix.dirname(filename);
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -146,9 +146,15 @@ export class App {
|
|
|
146
146
|
|
|
147
147
|
// second priority is a build configuration file.
|
|
148
148
|
} else if (jsonExists) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
try {
|
|
150
|
+
let content = JSON.parse(await readFile(jsonPath));
|
|
151
|
+
|
|
152
|
+
let builder = new ConfigFeature(content, featurePath);
|
|
153
|
+
await builder.build(this)
|
|
154
|
+
} catch (e) {
|
|
155
|
+
console.error(e);
|
|
156
|
+
throw e;
|
|
157
|
+
}
|
|
152
158
|
|
|
153
159
|
// if neither exist, assume the index should be added
|
|
154
160
|
} else if (indexExists) this.featureIndexes.push(indexPath);
|
|
@@ -173,7 +179,7 @@ export class App {
|
|
|
173
179
|
addLoadable(name, main, prefix) {
|
|
174
180
|
var dest = path.posix.join(this.sourcePath, main);
|
|
175
181
|
|
|
176
|
-
console.log(dest)
|
|
182
|
+
console.log('addLoadable', {name, path: dest, prefix})
|
|
177
183
|
this.loadables.push({name, path: dest, prefix});
|
|
178
184
|
}
|
|
179
185
|
|
|
@@ -218,8 +224,28 @@ export class App {
|
|
|
218
224
|
sourcemap: true,
|
|
219
225
|
dir : this.destination,
|
|
220
226
|
format: 'es',
|
|
227
|
+
assetFileNames: function(chunkInfo) {
|
|
228
|
+
return '[name]-[hash][extname]';
|
|
229
|
+
},
|
|
230
|
+
entryFileNames: function(chunkInfo) {
|
|
231
|
+
var entry = App.fixPath(chunkInfo.facadeModuleId);
|
|
232
|
+
var found = this.loadables.find(function(loadable) {
|
|
233
|
+
return loadable.path === entry;
|
|
234
|
+
}, this);
|
|
235
|
+
var exists = Boolean(found);
|
|
236
|
+
|
|
237
|
+
if (exists) return (`${found.name}.js`);
|
|
238
|
+
if (entry === this.fullIndexPath) {
|
|
239
|
+
return `${this.name}.js`
|
|
240
|
+
}
|
|
241
|
+
return '[name].js';
|
|
242
|
+
}.bind(this),
|
|
243
|
+
manualChunks: function(id) {
|
|
244
|
+
if (id.includes('node_modules')) {
|
|
245
|
+
return 'vendor';
|
|
246
|
+
}
|
|
247
|
+
}
|
|
221
248
|
},
|
|
222
|
-
assetFileNames: "[name]-[hash][extname]",
|
|
223
249
|
}
|
|
224
250
|
};
|
|
225
251
|
|
|
@@ -230,8 +256,6 @@ export class App {
|
|
|
230
256
|
await this.buildFeatures();
|
|
231
257
|
var config = this.buildConfiguration();
|
|
232
258
|
|
|
233
|
-
console.log(JSON.stringify(config, null, ' '));
|
|
234
|
-
|
|
235
259
|
const bundle = await rollup.rollup(config.input);
|
|
236
260
|
await bundle.generate(config.output);
|
|
237
261
|
await bundle.write(config.output);
|
package/ConfigApp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import App from './App';
|
|
2
2
|
import path from 'node:path/posix';
|
|
3
3
|
|
|
4
4
|
export default class ConfigApp extends App {
|
|
@@ -21,4 +21,4 @@ export default class ConfigApp extends App {
|
|
|
21
21
|
async getFeatures() {
|
|
22
22
|
return this.config.features || [];
|
|
23
23
|
}
|
|
24
|
-
}
|
|
24
|
+
}
|
package/ConfigFeature.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Feature from './Feature';
|
|
1
|
+
import Feature from './Feature.js';
|
|
2
2
|
|
|
3
|
-
export default class Feature {
|
|
3
|
+
export default class ConfigFeature extends Feature {
|
|
4
4
|
constructor (config, root) {
|
|
5
5
|
super();
|
|
6
6
|
this.config = config;
|
|
@@ -8,6 +8,8 @@ export default class Feature {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
async build(app) {
|
|
11
|
+
var config = this.config;
|
|
12
|
+
|
|
11
13
|
if (config.loadables && Array.isArray(config.loadables)) {
|
|
12
14
|
config.loadables.forEach(function(loadable) {
|
|
13
15
|
if (loadable.name && loadable.main) {
|
package/Feature.js
CHANGED
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import App from './App.js'
|
|
2
|
+
import Feature from './Feature.js';
|
|
3
3
|
|
|
4
|
-
export {App as App, Feature as Feature};
|
|
4
|
+
export {App as App, Feature as Feature};
|
package/package.json
CHANGED
package/plugin-loader.js
CHANGED
|
@@ -15,14 +15,14 @@ function makeSource(loadables) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
var switchStr = `
|
|
18
|
-
case '${loadable.name}':
|
|
18
|
+
case '${loadable.name}':
|
|
19
19
|
promise = import('${loadable.path}')${prefixStr}
|
|
20
20
|
break;
|
|
21
|
-
`
|
|
21
|
+
`
|
|
22
22
|
loadableSwitches += switchStr;
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
var source =
|
|
25
|
+
var source =
|
|
26
26
|
`
|
|
27
27
|
import {registry} from '@polylith/core';
|
|
28
28
|
|
|
@@ -35,14 +35,12 @@ ${loadableSwitches}
|
|
|
35
35
|
return promise;
|
|
36
36
|
}
|
|
37
37
|
`
|
|
38
|
-
console.log(source);
|
|
39
38
|
return source;
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
|
|
43
41
|
export default function loader(loadables) {
|
|
44
42
|
return {
|
|
45
|
-
name: 'loader',
|
|
43
|
+
name: 'loader',
|
|
46
44
|
|
|
47
45
|
resolveId (source, _, third) {
|
|
48
46
|
if (source === '@polylith/loader') {
|
|
@@ -59,4 +57,3 @@ export default function loader(loadables) {
|
|
|
59
57
|
}
|
|
60
58
|
};
|
|
61
59
|
}
|
|
62
|
-
|