@calmdown/rollup-plugin-copy 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/index.js +25 -23
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import * as fs from "node:fs/promises";
2
- import * as path from "node:path";
1
+ import * as FS from "node:fs/promises";
2
+ import * as Path from "node:path";
3
3
 
4
4
  const PLUGIN_NAME = "Copy";
5
5
 
@@ -59,15 +59,15 @@ export default function CopyPlugin(pluginOptions) {
59
59
  };
60
60
 
61
61
  const execTarget = async (context, cwd, target) => {
62
- const baseDir = target.baseDir ? path.resolve(cwd, target.baseDir) : cwd;
62
+ const baseDir = target.baseDir ? Path.resolve(cwd, target.baseDir) : cwd;
63
63
  const entries = [];
64
64
  if (target.srcFile) {
65
65
  // single file
66
- const src = path.resolve(baseDir, target.srcFile);
67
- const stats = await fs.stat(src);
66
+ const src = Path.resolve(baseDir, target.srcFile);
67
+ const stats = await FS.stat(src);
68
68
  entries.push({
69
69
  src,
70
- dst: path.resolve(baseDir, target.dstFile),
70
+ dst: Path.resolve(baseDir, target.dstFile),
71
71
  kind: getKind(stats),
72
72
  });
73
73
  }
@@ -80,12 +80,12 @@ export default function CopyPlugin(pluginOptions) {
80
80
  withFileTypes: true,
81
81
  };
82
82
 
83
- const dstDir = path.resolve(baseDir, target.dstDir);
83
+ const dstDir = Path.resolve(baseDir, target.dstDir);
84
84
  for (const includePattern of include) {
85
- for await (const entry of fs.glob(includePattern, globOptions)) {
85
+ for await (const entry of FS.glob(includePattern, globOptions)) {
86
86
  entries.push({
87
- src: path.join(entry.parentPath, entry.name),
88
- dst: path.join(dstDir, entry.name),
87
+ src: Path.join(entry.parentPath, entry.name),
88
+ dst: Path.join(dstDir, entry.name),
89
89
  kind: getKind(entry),
90
90
  });
91
91
  }
@@ -93,10 +93,10 @@ export default function CopyPlugin(pluginOptions) {
93
93
  }
94
94
 
95
95
  for (const entry of entries) {
96
- const dstDir = path.dirname(entry.dst);
96
+ const dstDir = Path.dirname(entry.dst);
97
97
  if (entry.kind === EK_FILE) {
98
- await exec(context, null, () => fs.mkdir(dstDir, { recursive: true }));
99
- await exec(context, `would copy file ${entry.src} -> ${entry.dst}`, () => fs.copyFile(entry.src, entry.dst));
98
+ await exec(context, null, () => FS.mkdir(dstDir, { recursive: true }));
99
+ await exec(context, `would copy file ${entry.src} -> ${entry.dst}`, () => FS.copyFile(entry.src, entry.dst));
100
100
  context.addWatchFile(entry.src);
101
101
  }
102
102
  else if (entry.kind === EK_LINK && symLinks !== SL_IGNORE) {
@@ -105,19 +105,19 @@ export default function CopyPlugin(pluginOptions) {
105
105
  continue;
106
106
  }
107
107
 
108
- await exec(context, null, () => fs.mkdir(dstDir, { recursive: true }));
108
+ await exec(context, null, () => FS.mkdir(dstDir, { recursive: true }));
109
109
  switch (symLinks) {
110
110
  case SL_COPY_FILE:
111
- await exec(context, `would copy file ${linkedPath} -> ${entry.dst} resolved from symlink ${entry.src}`, () => fs.copyFile(linkedPath, entry.dst));
111
+ await exec(context, `would copy file ${linkedPath} -> ${entry.dst} resolved from symlink ${entry.src}`, () => FS.copyFile(linkedPath, entry.dst));
112
112
  break;
113
113
 
114
114
  case SL_LINK_ABSOLUTE:
115
- await exec(context, `would create symlink ${entry.dst} pointing to ${linkedPath} resolved from symlink ${entry.src}`, () => fs.symlink(linkedPath, entry.dst));
115
+ await exec(context, `would create symlink ${entry.dst} pointing to ${linkedPath} resolved from symlink ${entry.src}`, () => FS.symlink(linkedPath, entry.dst));
116
116
  break;
117
117
 
118
118
  case SL_LINK_RELATIVE: {
119
- const linkTargetPath = path.relative(entry.dst, linkedPath);
120
- await exec(context, `would create symlink ${entry.dst} pointing to ${linkTargetPath} resolved from symlink ${entry.src}`, () => fs.symlink(linkTargetPath, entry.dst));
119
+ const linkTargetPath = Path.relative(entry.dst, linkedPath);
120
+ await exec(context, `would create symlink ${entry.dst} pointing to ${linkTargetPath} resolved from symlink ${entry.src}`, () => FS.symlink(linkTargetPath, entry.dst));
121
121
  break;
122
122
  }
123
123
  }
@@ -127,7 +127,6 @@ export default function CopyPlugin(pluginOptions) {
127
127
  }
128
128
  };
129
129
 
130
- let cwd = undefined;
131
130
  let isFirstBeforeRun = true;
132
131
  let isFirstAfterRun = true;
133
132
  return {
@@ -138,7 +137,8 @@ export default function CopyPlugin(pluginOptions) {
138
137
  }
139
138
 
140
139
  isFirstBeforeRun = false;
141
- cwd = process.cwd();
140
+
141
+ const cwd = process.cwd();
142
142
  for (const target of targets) {
143
143
  if (target.trigger === "before") {
144
144
  await execTarget(this, cwd, target);
@@ -151,6 +151,8 @@ export default function CopyPlugin(pluginOptions) {
151
151
  }
152
152
 
153
153
  isFirstAfterRun = false;
154
+
155
+ const cwd = process.cwd();
154
156
  for (const target of targets) {
155
157
  const { trigger } = target;
156
158
  if (trigger === "after" || trigger === undefined) {
@@ -183,15 +185,15 @@ async function resolveSymLink(linkPath, maxDepth = 8) {
183
185
  let current = linkPath;
184
186
  let depth = 0;
185
187
  do {
186
- const st = await fs.stat(current);
188
+ const st = await FS.stat(current);
187
189
  if (!st.isSymbolicLink()) {
188
190
  return current;
189
191
  }
190
192
 
191
- const target = await fs.readlink(current, "utf8");
193
+ const target = await FS.readlink(current, "utf8");
192
194
  visited.add(current);
193
195
 
194
- current = path.join(path.dirname(current), target);
196
+ current = Path.join(Path.dirname(current), target);
195
197
  }
196
198
  while (!visited.has(current) && ++depth < maxDepth);
197
199
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calmdown/rollup-plugin-copy",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "exports": {