wirejs-scripts 3.0.4 → 3.0.6
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/bin.js +32 -3
- package/configs/webpack.config.js +18 -19
- package/package.json +4 -2
package/bin.js
CHANGED
|
@@ -8,6 +8,7 @@ import path from 'path';
|
|
|
8
8
|
import webpack from 'webpack';
|
|
9
9
|
import webpackConfigure from './configs/webpack.config.js';
|
|
10
10
|
import { rimraf } from 'rimraf';
|
|
11
|
+
import esbuild from 'esbuild';
|
|
11
12
|
|
|
12
13
|
import { JSDOM } from 'jsdom';
|
|
13
14
|
import { useJSDOM } from 'wirejs-dom/v2';
|
|
@@ -72,7 +73,7 @@ async function callApiMethod(api, call, context) {
|
|
|
72
73
|
const [scope, ...rest] = call.method;
|
|
73
74
|
logger.info('api method parsed', { scope, rest });
|
|
74
75
|
if (rest.length === 0) {
|
|
75
|
-
logger.info('api method resolved. invoking...');
|
|
76
|
+
logger.info('api method resolved. invoking...', requiresContext(api[scope]));
|
|
76
77
|
if (requiresContext(api[scope])) {
|
|
77
78
|
return {
|
|
78
79
|
data: await api[scope](context, ...call.args.slice(1))
|
|
@@ -208,7 +209,7 @@ function byLength(a, b) {
|
|
|
208
209
|
* @returns
|
|
209
210
|
*/
|
|
210
211
|
function globMatch(pattern, text) {
|
|
211
|
-
const parts = pattern.split('
|
|
212
|
+
const parts = pattern.split('%');
|
|
212
213
|
const regex = new RegExp(parts.join('.+'));
|
|
213
214
|
return regex.test(text);
|
|
214
215
|
}
|
|
@@ -366,6 +367,14 @@ async function compile(watch = false) {
|
|
|
366
367
|
const stats = await new Promise(async (resolve, reject) => {
|
|
367
368
|
let compiler;
|
|
368
369
|
if (watch) {
|
|
370
|
+
const prebuild = await esbuild.context({
|
|
371
|
+
entryPoints: [`${CWD}/src/**/*.ts`],
|
|
372
|
+
outdir: `${CWD}/pre-dist`,
|
|
373
|
+
bundle: true,
|
|
374
|
+
format: 'esm',
|
|
375
|
+
conditions: ['wirejs:client'],
|
|
376
|
+
});
|
|
377
|
+
prebuild.watch();
|
|
369
378
|
webpack({
|
|
370
379
|
...webpackConfig,
|
|
371
380
|
mode: 'development',
|
|
@@ -382,6 +391,13 @@ async function compile(watch = false) {
|
|
|
382
391
|
});
|
|
383
392
|
} else {
|
|
384
393
|
logger.log('instantiating webpack compiler');
|
|
394
|
+
await esbuild.build({
|
|
395
|
+
entryPoints: [`${CWD}/src/**/*.ts`],
|
|
396
|
+
outdir: `${CWD}/pre-dist`,
|
|
397
|
+
bundle: true,
|
|
398
|
+
format: 'esm',
|
|
399
|
+
conditions: ['wirejs:client'],
|
|
400
|
+
});
|
|
385
401
|
compiler = webpack(webpackConfig);
|
|
386
402
|
compiler.run((err, res) => {
|
|
387
403
|
logger.log('invoking webpack compiler');
|
|
@@ -415,6 +431,12 @@ const engine = {
|
|
|
415
431
|
fs.mkdirSync('dist');
|
|
416
432
|
logger.log('recreated dist folder');
|
|
417
433
|
|
|
434
|
+
rimraf.sync('pre-dist');
|
|
435
|
+
logger.log('cleared old pre-dist folder');
|
|
436
|
+
|
|
437
|
+
fs.mkdirSync('pre-dist');
|
|
438
|
+
logger.log('recreated pre-dist folder');
|
|
439
|
+
|
|
418
440
|
try {
|
|
419
441
|
await compile(watch);
|
|
420
442
|
logger.log('finished compile');
|
|
@@ -444,7 +466,14 @@ const engine = {
|
|
|
444
466
|
},
|
|
445
467
|
|
|
446
468
|
async ['prebuild-api']() {
|
|
447
|
-
logger.log("prebuilding api...");
|
|
469
|
+
logger.log("prebuilding api ...");
|
|
470
|
+
await esbuild.build({
|
|
471
|
+
entryPoints: [`${CWD}/**/*.ts`],
|
|
472
|
+
outdir: CWD,
|
|
473
|
+
platform: 'node',
|
|
474
|
+
bundle: false,
|
|
475
|
+
format: 'esm',
|
|
476
|
+
});
|
|
448
477
|
await prebuildApi();
|
|
449
478
|
logger.log("api prebuild finished");
|
|
450
479
|
},
|
|
@@ -9,6 +9,7 @@ import { JSDOM } from 'jsdom';
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
const CWD = process.cwd();
|
|
12
|
+
const SRC = 'pre-dist';
|
|
12
13
|
|
|
13
14
|
// https://marked.js.org/using_advanced
|
|
14
15
|
marked.setOptions({
|
|
@@ -68,7 +69,7 @@ const SSG = {
|
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
const layoutPath = path.join(
|
|
71
|
-
|
|
72
|
+
SRC,
|
|
72
73
|
'layouts',
|
|
73
74
|
(_meta.layout || 'default')
|
|
74
75
|
) + '.html';
|
|
@@ -103,7 +104,7 @@ const Generated = {
|
|
|
103
104
|
|
|
104
105
|
if (hydrationsFound) {
|
|
105
106
|
const script = doc.parentNode.createElement('script');
|
|
106
|
-
script.src = contentPath.substring((CWD
|
|
107
|
+
script.src = contentPath.substring((`${CWD}/${SRC}/ssg`).length);
|
|
107
108
|
doc.parentNode.body.appendChild(script);
|
|
108
109
|
}
|
|
109
110
|
|
|
@@ -130,23 +131,21 @@ export default (env, argv) => {
|
|
|
130
131
|
devtool = 'eval-cheap-source-map';
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
const sources = [
|
|
134
|
-
.concat(glob.sync(
|
|
135
|
-
.concat(glob.sync(
|
|
136
|
-
.concat(glob.sync('./src/ssg/**/*.js'))
|
|
137
|
-
.concat(glob.sync('./src/ssr/**/*.js'))
|
|
134
|
+
const sources = [`./${SRC}/index.{js,ts}`]
|
|
135
|
+
.concat(glob.sync(`./${SRC}/ssg/**/*.{js,ts}`))
|
|
136
|
+
.concat(glob.sync(`./${SRC}/ssr/**/*.{js,ts}`))
|
|
138
137
|
;
|
|
139
138
|
|
|
140
139
|
const entry = sources.reduce((files, path) => {
|
|
141
|
-
if (path.match(/
|
|
142
|
-
files[path.toString().slice(
|
|
143
|
-
} else if (path.match(/
|
|
140
|
+
if (path.match(new RegExp(`${SRC}/ssg`))) {
|
|
141
|
+
files[path.toString().slice(`./${SRC}/ssg`.length)] = path;
|
|
142
|
+
} else if (path.match(new RegExp(`${SRC}/ssr`))) {
|
|
144
143
|
// keep SSR bundles in the ssr subfolder
|
|
145
|
-
files[path.toString().slice(
|
|
146
|
-
} else if (path.match(/
|
|
147
|
-
files[path.toString().slice(
|
|
148
|
-
} else if (path.match(/
|
|
149
|
-
files[path.toString().slice(
|
|
144
|
+
files[path.toString().slice(`./${SRC}`.length)] = path;
|
|
145
|
+
} else if (path.match(new RegExp(`${SRC}/routes`))) {
|
|
146
|
+
files[path.toString().slice(`./${SRC}/routes`.length)] = path;
|
|
147
|
+
} else if (path.match(new RegExp(`${SRC}/layouts`))) {
|
|
148
|
+
files[path.toString().slice(`./${SRC}/`.length)] = path;
|
|
150
149
|
}
|
|
151
150
|
return files;
|
|
152
151
|
}, {});
|
|
@@ -186,9 +185,9 @@ export default (env, argv) => {
|
|
|
186
185
|
new CopyWebpackPlugin({
|
|
187
186
|
patterns: [
|
|
188
187
|
{
|
|
189
|
-
from:
|
|
188
|
+
from: `./${SRC}/layouts/**/*.html`,
|
|
190
189
|
to: distPath({
|
|
191
|
-
subpathIn:
|
|
190
|
+
subpathIn: `${SRC}/layouts`,
|
|
192
191
|
subpathOut: 'layouts'
|
|
193
192
|
}),
|
|
194
193
|
transform: CollectLayouts,
|
|
@@ -206,8 +205,8 @@ export default (env, argv) => {
|
|
|
206
205
|
priority: 10,
|
|
207
206
|
},
|
|
208
207
|
{
|
|
209
|
-
from:
|
|
210
|
-
to: distPath({ subpathIn:
|
|
208
|
+
from: `./${SRC}/ssg/**/*.{js,ts}`,
|
|
209
|
+
to: distPath({ subpathIn: `${SRC}/ssg`, extensionOut: 'html' }),
|
|
211
210
|
transform: Generated,
|
|
212
211
|
noErrorOnMissing: true,
|
|
213
212
|
priority: 5
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-scripts",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "Basic build and start commands for wirejs apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"copy-webpack-plugin": "^10.2.4",
|
|
25
25
|
"css-loader": "^5.2.0",
|
|
26
|
+
"esbuild": "^0.24.2",
|
|
26
27
|
"file-loader": "^6.2.0",
|
|
27
28
|
"glob": "^7.2.0",
|
|
28
29
|
"jsdom": "^25.0.1",
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"rimraf": "^6.0.1",
|
|
32
33
|
"style-loader": "^2.0.0",
|
|
33
34
|
"webpack": "^5.97.1",
|
|
34
|
-
"wirejs-dom": "^1.0.
|
|
35
|
+
"wirejs-dom": "^1.0.38",
|
|
36
|
+
"wirejs-resources": "^0.1.9"
|
|
35
37
|
}
|
|
36
38
|
}
|