@michijs/dev-server 0.8.2 → 0.8.3

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.
@@ -1,6 +1,5 @@
1
1
  import type { Transformer } from "../../utils/copy.js";
2
2
  export declare const jsAndTsRegex: RegExp;
3
- export declare const notJsAndTsRegex: RegExp;
4
3
  export declare const jsonTransformer: {
5
4
  fileRegex: RegExp;
6
5
  transformer: (fileContent: string) => string;
@@ -3,7 +3,6 @@ import { minifyXMLLike } from "../../utils/minify.js";
3
3
  import { workerTransformer } from "../../utils/workerTransformer.js";
4
4
  import { transformSync as esbuild } from "esbuild";
5
5
  export const jsAndTsRegex = /.*\.(?:ts|js)/;
6
- export const notJsAndTsRegex = /.*\.(?!ts|js)/;
7
6
  export const jsonTransformer = {
8
7
  fileRegex: /.*\.(?:json)/,
9
8
  transformer: (fileContent) => config.public.minify
@@ -1,5 +1,5 @@
1
1
  import { config, connections } from "../config.js";
2
- import { jsAndTsRegex, notJsAndTsRegex, transformers, } from "../../actions/start/transformers.js";
2
+ import { transformers } from "../../actions/start/transformers.js";
3
3
  import { syncDirs } from "../../utils/syncDirs.js";
4
4
  import { copy } from "../../utils/copy.js";
5
5
  import fs from "fs";
@@ -34,13 +34,11 @@ export const publicFolderPlugin = {
34
34
  fs.writeFileSync(getPath(`${wellKnownDir}/web-app-origin-association`), transformedFile);
35
35
  }
36
36
  }
37
- // Copy public path - Omit to copy service worker - will be transformed after
38
- copy(config.public.path, outdir, transformers, [jsAndTsRegex]);
37
+ copy(config.public.path, outdir, transformers);
39
38
  let firstLoad = true;
40
39
  build.onEnd(() => {
41
- // first-load sw - Omit to copy any other non-js file
42
40
  if (firstLoad) {
43
- copy(config.public.path, outdir, transformers, [notJsAndTsRegex]);
41
+ copy(config.public.path, outdir, transformers);
44
42
  if (config.watch)
45
43
  syncDirs(config.public.path, config.esbuildOptions.outdir, transformers, undefined, undefined, (event, fileChangedPath) => {
46
44
  connections.forEach((x) => x.write(`event: change\ndata: ${JSON.stringify({
package/bin/utils/copy.js CHANGED
@@ -2,30 +2,25 @@ import fs from "fs";
2
2
  import { getPath } from "./getPath.js";
3
3
  export function copyFile(src, fileName, dest, transformers, omit) {
4
4
  const srcPath = getPath(`${src}/${fileName}`);
5
- if (!omit?.find((x) => x.test(srcPath))) {
6
- const destPath = getPath(`${dest}/${fileName}`);
7
- if (fs.lstatSync(srcPath).isDirectory()) {
8
- copy(srcPath, destPath, transformers, omit);
5
+ const destPath = getPath(`${dest}/${fileName}`);
6
+ if (fs.lstatSync(srcPath).isDirectory())
7
+ return copy(srcPath, destPath, transformers, omit);
8
+ if (omit?.find((x) => x.test(srcPath)))
9
+ return;
10
+ const fileTransformer = transformers?.filter((x) => x.fileRegex.test(fileName));
11
+ if (fileTransformer.length === 0)
12
+ return fs.copyFileSync(srcPath, destPath, fs.constants.COPYFILE_FICLONE);
13
+ fileTransformer.forEach(async (x) => {
14
+ const srcFileContent = fs.readFileSync(srcPath, {
15
+ encoding: "utf-8",
16
+ });
17
+ const finalDestPath = x.pathTransformer?.(destPath) ?? destPath;
18
+ try {
19
+ const transformedFile = x.transformer(srcFileContent, srcPath);
20
+ fs.writeFileSync(finalDestPath, transformedFile);
9
21
  }
10
- else {
11
- const fileTransformer = transformers?.filter((x) => x.fileRegex.test(fileName));
12
- if (fileTransformer.length > 0) {
13
- fileTransformer.forEach(async (x) => {
14
- const srcFileContent = fs.readFileSync(srcPath, {
15
- encoding: "utf-8",
16
- });
17
- const finalDestPath = x.pathTransformer?.(destPath) ?? destPath;
18
- try {
19
- const transformedFile = x.transformer(srcFileContent, srcPath);
20
- fs.writeFileSync(finalDestPath, transformedFile);
21
- }
22
- catch { }
23
- });
24
- }
25
- else
26
- fs.copyFileSync(srcPath, destPath, fs.constants.COPYFILE_FICLONE);
27
- }
28
- }
22
+ catch { }
23
+ });
29
24
  }
30
25
  export function copy(src, dest, transformers, omit) {
31
26
  const srcDir = fs.readdirSync(src);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@michijs/dev-server",
3
3
  "license": "MIT",
4
- "version": "0.8.2",
4
+ "version": "0.8.3",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/michijs/dev-server.git"