Skip to content

Commit

Permalink
release(esbuild): 🏹 Release esbuild-plugin-copy@2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
linbudu599 committed Jan 19, 2023
1 parent d845f5c commit fee3466
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-copy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esbuild-plugin-copy",
"version": "2.0.1",
"version": "2.0.2",
"description": "ESBuild plugin for assets copy.",
"keywords": [
"esbuild",
Expand Down
32 changes: 23 additions & 9 deletions packages/esbuild-plugin-copy/src/lib/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function copyOperationHandler(
rawFromPath: string[],
globbedFromPath: string,
baseToPath: string,

verbose = false,
dryRun = false
) {
Expand Down Expand Up @@ -53,16 +54,29 @@ export function copyOperationHandler(
// path.resolve seems to be unnecessary as globbed path is already absolute path
const sourcePath = path.resolve(globbedFromPath);

const composedDistDirPath = path.resolve(
// base resolve destination dir
outDirResolveFrom,
// configures destination dir
baseToPath,
// internal dir structure, remove the first slash
preservedDirStructure.slice(1)
);
const isToPathDir = path.extname(baseToPath) === '';

const composedDistDirPath = isToPathDir
? path.resolve(
// base resolve destination dir
outDirResolveFrom,
// configures destination dir
baseToPath,
// internal dir structure, remove the first slash
preservedDirStructure.slice(1)
)
: path.resolve(
// base resolve destination dir
outDirResolveFrom,
// configures destination dir
baseToPath
);

dryRun ? void 0 : fs.ensureDirSync(path.dirname(composedDistDirPath));
dryRun
? void 0
: isToPathDir
? fs.ensureDirSync(path.dirname(composedDistDirPath))
: void 0;
dryRun ? void 0 : fs.copyFileSync(sourcePath, composedDistDirPath);

verboseLog(
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-copy/src/lib/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface Options {
* also, you can specify somewhere else to resolve from.
* @default "out"
*/
resolveFrom: 'cwd' | 'out' | string;
resolveFrom: 'cwd' | 'out' | (string & {});

/**
* use dry run mode to see what's happening.
Expand Down
22 changes: 22 additions & 0 deletions packages/esbuild-plugin-copy/tests/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,28 @@ describe('CopyPlugin:Core', async () => {
);
expect(d3).toEqual(['deep.txt']);
});

it('should copy from file to file', async () => {
const outDir = tmp.dirSync().name;

await builder(
outDir,
{ outdir: outDir },
{
assets: {
from: path.resolve(__dirname, './fixtures/assets/note.txt'),
to: 'hello.txt',
},
resolveFrom: outDir,
verbose: false,
dryRun: false,
}
);

const d1 = fs.readdirSync(path.join(outDir), {});

expect(d1).toEqual(['hello.txt', 'index.js']);
});
});

describe('CopyPlugin:Utils', async () => {
Expand Down

0 comments on commit fee3466

Please sign in to comment.