@michijs/dev-server 0.7.16 → 0.7.18
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/actions/start.js +0 -2
- package/bin/config/config.js +3 -12
- package/bin/config/plugins/publicFolder.d.ts +2 -0
- package/bin/config/plugins/publicFolder.js +32 -0
- package/bin/utils/syncDirs.js +2 -0
- package/package.json +4 -4
- package/bin/config/plugins/watchPublicFolder.d.ts +0 -2
- package/bin/config/plugins/watchPublicFolder.js +0 -16
package/bin/actions/start.js
CHANGED
|
@@ -7,9 +7,7 @@ import open from "open";
|
|
|
7
7
|
import { context } from "esbuild";
|
|
8
8
|
import { getHostURL } from "../utils/getHostURL.js";
|
|
9
9
|
import { getLocalURL } from "../utils/getLocalURL.js";
|
|
10
|
-
import { watchPublicFolderPlugin } from "../config/plugins/watchPublicFolder.js";
|
|
11
10
|
export const start = async (callback) => {
|
|
12
|
-
config.esbuildOptions.plugins?.push(watchPublicFolderPlugin);
|
|
13
11
|
const buildContext = await context(config.esbuildOptions);
|
|
14
12
|
const { host: esbuildHost, port: esbuildPort } = await buildContext.serve({
|
|
15
13
|
servedir: config.esbuildOptions.outdir,
|
package/bin/config/config.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import coloredString from "../utils/coloredString.js";
|
|
3
|
-
import { copy } from "../utils/copy.js";
|
|
4
3
|
import { getPath } from "../utils/getPath.js";
|
|
5
4
|
import { userConfig } from "./userConfig.js";
|
|
6
5
|
import { resolve } from "path";
|
|
7
|
-
import {
|
|
6
|
+
import { jsonTransformer } from "../actions/start/transformers.js";
|
|
8
7
|
import { dirname } from "path";
|
|
9
8
|
import { fileURLToPath } from "url";
|
|
10
9
|
import { counterPlugin } from "./plugins/counter.js";
|
|
11
10
|
import { getCurrentCommitSha } from "../utils/getCurrentCommitSha.js";
|
|
11
|
+
import { publicFolderPlugin } from "./plugins/publicFolder.js";
|
|
12
12
|
const minify = process.env.NODE_ENV === "PRODUCTION";
|
|
13
13
|
const devServerListener = process.env.NODE_ENV === "DEVELOPMENT"
|
|
14
14
|
? [getPath(`${dirname(fileURLToPath(import.meta.url))}/public/client.js`)]
|
|
@@ -88,6 +88,7 @@ const config = {
|
|
|
88
88
|
// ],
|
|
89
89
|
plugins: [
|
|
90
90
|
...(userConfig.esbuildOptions?.plugins ?? []),
|
|
91
|
+
publicFolderPlugin,
|
|
91
92
|
{
|
|
92
93
|
name: "michijs-dev-server",
|
|
93
94
|
setup(build) {
|
|
@@ -115,16 +116,6 @@ const config = {
|
|
|
115
116
|
fs.writeFileSync(getPath(`${wellKnownDir}/web-app-origin-association`), transformedFile);
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
|
-
// Copy public path - Omit to copy service worker - will be transformed after
|
|
119
|
-
if (config.public.path && build.initialOptions.outdir)
|
|
120
|
-
copy(config.public.path, build.initialOptions.outdir, transformers, [jsAndTsRegex]);
|
|
121
|
-
let firstLoad = true;
|
|
122
|
-
build.onEnd(() => {
|
|
123
|
-
// first-load sw - Omit to copy any other non-js file
|
|
124
|
-
if (firstLoad && config.public.path && build.initialOptions.outdir)
|
|
125
|
-
copy(config.public.path, build.initialOptions.outdir, transformers, [notJsAndTsRegex]);
|
|
126
|
-
firstLoad = false;
|
|
127
|
-
});
|
|
128
119
|
},
|
|
129
120
|
},
|
|
130
121
|
counterPlugin,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { config, connections } from "../config.js";
|
|
2
|
+
import { jsAndTsRegex, notJsAndTsRegex, transformers, } from "../../actions/start/transformers.js";
|
|
3
|
+
import { syncDirs } from "../../utils/syncDirs.js";
|
|
4
|
+
import { copy } from "../../utils/copy.js";
|
|
5
|
+
export const publicFolderPlugin = {
|
|
6
|
+
name: "michijs-dev-server-public-folder",
|
|
7
|
+
setup(build) {
|
|
8
|
+
// Copy public path - Omit to copy service worker - will be transformed after
|
|
9
|
+
if (build.initialOptions.outdir)
|
|
10
|
+
copy(config.public.path, build.initialOptions.outdir, transformers, [
|
|
11
|
+
jsAndTsRegex,
|
|
12
|
+
]);
|
|
13
|
+
let firstLoad = true;
|
|
14
|
+
build.onEnd(() => {
|
|
15
|
+
// first-load sw - Omit to copy any other non-js file
|
|
16
|
+
if (firstLoad && build.initialOptions.outdir) {
|
|
17
|
+
copy(config.public.path, build.initialOptions.outdir, transformers, [
|
|
18
|
+
notJsAndTsRegex,
|
|
19
|
+
]);
|
|
20
|
+
if (config.watch)
|
|
21
|
+
syncDirs(config.public.path, config.esbuildOptions.outdir, transformers, undefined, undefined, (event, fileChangedPath) => {
|
|
22
|
+
connections.forEach((x) => x.write(`event: change\ndata: ${JSON.stringify({
|
|
23
|
+
added: [],
|
|
24
|
+
removed: event === "remove" ? [fileChangedPath] : [],
|
|
25
|
+
updated: event === "update" ? [fileChangedPath] : [],
|
|
26
|
+
})}\n\n`));
|
|
27
|
+
});
|
|
28
|
+
firstLoad = false;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
};
|
package/bin/utils/syncDirs.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from "path";
|
|
|
3
3
|
import { copyFile } from "../utils/copy.js";
|
|
4
4
|
import watch from "node-watch";
|
|
5
5
|
import { getPath } from "../utils/getPath.js";
|
|
6
|
+
import coloredString from "./coloredString.js";
|
|
6
7
|
export const syncDirs = (srcDir, outDir, transformers, omit, onStartSync, onEndSync) => {
|
|
7
8
|
watch.default(srcDir, {
|
|
8
9
|
encoding: "utf-8",
|
|
@@ -14,6 +15,7 @@ export const syncDirs = (srcDir, outDir, transformers, omit, onStartSync, onEndS
|
|
|
14
15
|
const fileName = path.basename(fileChangedPath);
|
|
15
16
|
const fileOutDir = fileSrcDir.replace(srcDir, outDir);
|
|
16
17
|
const pathToRemove = getPath(`${fileOutDir}/${fileName}`);
|
|
18
|
+
console.log(` ${coloredString(`File ${fileChangedPath} ${event}.`)}`);
|
|
17
19
|
if (event === "remove")
|
|
18
20
|
transformers.forEach((x) => {
|
|
19
21
|
if (x.fileRegex.test(fileChangedPath)) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@michijs/dev-server",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.18",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/michijs/dev-server.git"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@michijs/tsconfig": "0.0.4",
|
|
33
|
-
"@types/node": "22.
|
|
33
|
+
"@types/node": "22.7.4",
|
|
34
34
|
"@types/yargs": "17.0.33",
|
|
35
35
|
"typescript": "5.6.2"
|
|
36
36
|
},
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"colorthief": "2.4.0",
|
|
57
57
|
"@types/web-app-manifest": "1.0.8",
|
|
58
|
-
"esbuild": "0.
|
|
58
|
+
"esbuild": "0.24.0",
|
|
59
59
|
"node-watch": "0.7.4",
|
|
60
60
|
"open": "10.1.0",
|
|
61
|
-
"playwright-core": "1.47.
|
|
61
|
+
"playwright-core": "1.47.2",
|
|
62
62
|
"sharp": "0.33.5",
|
|
63
63
|
"yargs": "17.7.2"
|
|
64
64
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { config, connections } from "../../config/config.js";
|
|
2
|
-
import { transformers } from "../../actions/start/transformers.js";
|
|
3
|
-
import { syncDirs } from "../../utils/syncDirs.js";
|
|
4
|
-
export const watchPublicFolderPlugin = {
|
|
5
|
-
name: "michijs-dev-server-watch-public-folder",
|
|
6
|
-
setup() {
|
|
7
|
-
if (config.public.path && config.watch)
|
|
8
|
-
syncDirs(config.public.path, config.esbuildOptions.outdir, transformers, undefined, undefined, (event, fileChangedPath) => {
|
|
9
|
-
connections.forEach((x) => x.write(`event: change\ndata: ${JSON.stringify({
|
|
10
|
-
added: [],
|
|
11
|
-
removed: event === "remove" ? [fileChangedPath] : [],
|
|
12
|
-
updated: event === "update" ? [fileChangedPath] : [],
|
|
13
|
-
})}\n\n`));
|
|
14
|
-
});
|
|
15
|
-
},
|
|
16
|
-
};
|