Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Sparky().dest() does not interpret its arguments as relative paths. #1961

Open
SephReed opened this issue Nov 15, 2020 · 1 comment
Open

Comments

@SephReed
Copy link
Contributor

SephReed commented Nov 15, 2020

#1808

I figured out what was causing the issue. This comment can be skipped, but has been left to show the work.

Sparky has some messed up logic around saving files in new locations:

if (newLocation && newLocationBase) {
const root = ensureAbsolutePath(newLocation, env.SCRIPT_PATH);
for (const i in latest) {
const file = latest[i];
readFiles[file] = readFiles[file] || readFileAsBuffer(file);
// normalize path so split works with windows path
const s = path.normalize(ensureFuseBoxPath(file)).split(newLocationBase);
if (!s[1]) {
log.error(`Can't find base of ${newLocationBase} of ${file}`);
return;
} else {
const newFileLocation = path.join(root, s[1]);
ensureDir(path.dirname(newFileLocation));
await writeFile(newFileLocation, readFiles[file]);
}
}
}

It appears the logic for resource files got put into the core logic for sparky, so now it is only capable of saving files in folders with their filetype name.

This line in particular is where the bug happens:

// join root and the file extension to create a folder such as dist/png or dist/svg
const newFileLocation = path.join(root, s[1]); 

This line is also buggy:

// only files that have an extension are capable of being copied?
if (!s[1]) { 
       log.error(`Can't find base of ${newLocationBase} of ${file}`); 

Also, it doesn't appear the filename ever gets added back to the folder its being put in:

// newFileLocation is just dist/png.   It still hasn't had the actual filename appended??
await writeFile(newFileLocation, readFiles[file]); 
@SephReed
Copy link
Contributor Author

Never mind. I figured out the issue. I was using . as my base for dest():

task("default", async () => {
  await src("./assets/**/**.**")
    .dest("./dist/", ".")
    .exec();
});

I thought it would be interpreted as a relative path by dest, but it's stored as a simple string:

dest: (target: string, base: string) => {
newLocation = target;
newLocationBase = base;
return chain;
},

And then later used to split the file path to figure out what it's relative path should be in dist:

const s = path.normalize(ensureFuseBoxPath(file)).split(newLocationBase);

By using a dot, I was splitting the filename from the file extension.


I'm leaving this issue open but changing the name. sparky().dest("./dist", "./assets") should probably be interpreted as changing the destination from whatever it is in assets to whatever it is in dist.

@SephReed SephReed changed the title Fix Spark newLocation && newLocationBase logic Sparky().dest() does not interpret its arguments as relative paths. Nov 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant