@prostojs/rewrite 0.2.1 → 0.2.2

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/dist/index.cjs CHANGED
@@ -35,7 +35,7 @@ async function getPath() {
35
35
  return _path;
36
36
  }
37
37
  async function readDir(dirPath) {
38
- if (__NODE_JS__) {
38
+ {
39
39
  const path = await getPath();
40
40
  const fs = await getFs();
41
41
  async function* getFiles(dir) {
@@ -51,7 +51,7 @@ async function readDir(dirPath) {
51
51
  throw new Error(errorMessage);
52
52
  }
53
53
  async function readFile(filePath) {
54
- if (__NODE_JS__) {
54
+ {
55
55
  const fs = await getFs();
56
56
  try {
57
57
  return (await fs.promises.readFile(filePath)).toString();
@@ -62,7 +62,7 @@ async function readFile(filePath) {
62
62
  throw new Error(errorMessage);
63
63
  }
64
64
  async function writeFile(targetPath, data) {
65
- if (__NODE_JS__) {
65
+ {
66
66
  const path = await getPath();
67
67
  const fs = await getFs();
68
68
  const dirname = path.dirname(targetPath);
@@ -73,7 +73,7 @@ async function writeFile(targetPath, data) {
73
73
  throw new Error(errorMessage);
74
74
  }
75
75
  async function copyFile(filePath, targetPath) {
76
- if (__NODE_JS__) {
76
+ {
77
77
  if (filePath === targetPath) return;
78
78
  const path = await getPath();
79
79
  const fs = await getFs();
@@ -85,12 +85,10 @@ async function copyFile(filePath, targetPath) {
85
85
  throw new Error(errorMessage);
86
86
  }
87
87
  async function pathResolve(p) {
88
- if (__NODE_JS__) return (await getPath()).resolve(p);
89
- throw new Error(errorMessage);
88
+ return (await getPath()).resolve(p);
90
89
  }
91
90
  async function pathJoin(...parts) {
92
- if (__NODE_JS__) return (await getPath()).join(...parts);
93
- throw new Error(errorMessage);
91
+ return (await getPath()).join(...parts);
94
92
  }
95
93
  //#endregion
96
94
  //#region src/string-expression.ts
@@ -743,13 +741,13 @@ var ProstoRewrite = class {
743
741
  this.options = {
744
742
  defaultMode: options?.defaultMode || "auto",
745
743
  debug: options?.debug || false,
746
- htmlPattern: __NODE_JS__ ? (options?.htmlPattern || ["*.{html,xhtml,xml,svg}"]).map((p) => new minimatch.Minimatch(p, { matchBase: true })) : [],
747
- textPattern: __NODE_JS__ ? (options?.textPattern || [
744
+ htmlPattern: (options?.htmlPattern || ["*.{html,xhtml,xml,svg}"]).map((p) => new minimatch.Minimatch(p, { matchBase: true })),
745
+ textPattern: (options?.textPattern || [
748
746
  "*.{js,jsx,ts,tsx,txt,json,yml,yaml,md,ini}",
749
747
  "Dockerfile",
750
748
  "*config",
751
749
  ".gitignore"
752
- ]).map((p) => new minimatch.Minimatch(p, { matchBase: true })) : [],
750
+ ]).map((p) => new minimatch.Minimatch(p, { matchBase: true })),
753
751
  html: {
754
752
  exprDelimiters: defaultDelimiters,
755
753
  attrExpression: ":",
@@ -807,7 +805,6 @@ var ProstoRewrite = class {
807
805
  return output;
808
806
  }
809
807
  async rewriteDir(opts, context) {
810
- if (__BROWSER__) return;
811
808
  const files = await readDir(opts.baseDir);
812
809
  const dirPath = await pathResolve(opts.baseDir);
813
810
  const include = opts.include && opts.include.length ? opts.include.map((s) => new minimatch.Minimatch(s, { matchBase: true })) : null;
package/dist/index.mjs CHANGED
@@ -34,7 +34,7 @@ async function getPath() {
34
34
  return _path;
35
35
  }
36
36
  async function readDir(dirPath) {
37
- if (__NODE_JS__) {
37
+ {
38
38
  const path = await getPath();
39
39
  const fs = await getFs();
40
40
  async function* getFiles(dir) {
@@ -50,7 +50,7 @@ async function readDir(dirPath) {
50
50
  throw new Error(errorMessage);
51
51
  }
52
52
  async function readFile(filePath) {
53
- if (__NODE_JS__) {
53
+ {
54
54
  const fs = await getFs();
55
55
  try {
56
56
  return (await fs.promises.readFile(filePath)).toString();
@@ -61,7 +61,7 @@ async function readFile(filePath) {
61
61
  throw new Error(errorMessage);
62
62
  }
63
63
  async function writeFile(targetPath, data) {
64
- if (__NODE_JS__) {
64
+ {
65
65
  const path = await getPath();
66
66
  const fs = await getFs();
67
67
  const dirname = path.dirname(targetPath);
@@ -72,7 +72,7 @@ async function writeFile(targetPath, data) {
72
72
  throw new Error(errorMessage);
73
73
  }
74
74
  async function copyFile(filePath, targetPath) {
75
- if (__NODE_JS__) {
75
+ {
76
76
  if (filePath === targetPath) return;
77
77
  const path = await getPath();
78
78
  const fs = await getFs();
@@ -84,12 +84,10 @@ async function copyFile(filePath, targetPath) {
84
84
  throw new Error(errorMessage);
85
85
  }
86
86
  async function pathResolve(p) {
87
- if (__NODE_JS__) return (await getPath()).resolve(p);
88
- throw new Error(errorMessage);
87
+ return (await getPath()).resolve(p);
89
88
  }
90
89
  async function pathJoin(...parts) {
91
- if (__NODE_JS__) return (await getPath()).join(...parts);
92
- throw new Error(errorMessage);
90
+ return (await getPath()).join(...parts);
93
91
  }
94
92
  //#endregion
95
93
  //#region src/string-expression.ts
@@ -742,13 +740,13 @@ var ProstoRewrite = class {
742
740
  this.options = {
743
741
  defaultMode: options?.defaultMode || "auto",
744
742
  debug: options?.debug || false,
745
- htmlPattern: __NODE_JS__ ? (options?.htmlPattern || ["*.{html,xhtml,xml,svg}"]).map((p) => new Minimatch(p, { matchBase: true })) : [],
746
- textPattern: __NODE_JS__ ? (options?.textPattern || [
743
+ htmlPattern: (options?.htmlPattern || ["*.{html,xhtml,xml,svg}"]).map((p) => new Minimatch(p, { matchBase: true })),
744
+ textPattern: (options?.textPattern || [
747
745
  "*.{js,jsx,ts,tsx,txt,json,yml,yaml,md,ini}",
748
746
  "Dockerfile",
749
747
  "*config",
750
748
  ".gitignore"
751
- ]).map((p) => new Minimatch(p, { matchBase: true })) : [],
749
+ ]).map((p) => new Minimatch(p, { matchBase: true })),
752
750
  html: {
753
751
  exprDelimiters: defaultDelimiters,
754
752
  attrExpression: ":",
@@ -806,7 +804,6 @@ var ProstoRewrite = class {
806
804
  return output;
807
805
  }
808
806
  async rewriteDir(opts, context) {
809
- if (__BROWSER__) return;
810
807
  const files = await readDir(opts.baseDir);
811
808
  const dirPath = await pathResolve(opts.baseDir);
812
809
  const include = opts.include && opts.include.length ? opts.include.map((s) => new Minimatch(s, { matchBase: true })) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prostojs/rewrite",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Easy and light templates renderer",
5
5
  "keywords": [
6
6
  "prostojs",