Thanks to visit codestin.com
Credit goes to github.com

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

Commit 54f3828

Browse files
karlbohlmarknchanged
authored andcommitted
feat: Handle resolve urls including protocol
1 parent 785cd8f commit 54f3828

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ export function ensureAbsolutePath(userPath: string) {
146146
return userPath;
147147
}
148148
export function joinFuseBoxPath(...any): string {
149-
return ensureFuseBoxPath(path.join(...any));
149+
let includesProtocol = any[0].includes('://');
150+
let joinedPath = !includesProtocol
151+
? path.join(...any)
152+
: any[0].replace(/([^/])$/, '$1/') + path.join(...any.slice(1));
153+
return ensureFuseBoxPath(joinedPath);
150154
}
151155
export function ensureDir(userPath: string) {
152156
if (!path.isAbsolute(userPath)) {

src/tests/plugins/CopyPlugin.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,21 @@ export class CssPluginTest {
141141
should(result.projectContents.toString()).findString(`module.exports.default = "/static/92849cf0-hello.txt";`);
142142
});
143143
}
144+
145+
"Should copy a file with custom resolver to external domain (hash)"() {
146+
return createEnv({
147+
project: {
148+
hash: true,
149+
files: {
150+
"index.ts": `require("./hello.txt")`,
151+
"hello.txt": "ololo",
152+
},
153+
plugins: [CopyPlugin({ resolve: "https://example.com/static/", files: [".txt"] })],
154+
instructions: "> index.ts",
155+
},
156+
}).then(result => {
157+
result.shouldExistInDist("assets/92849cf0-hello.txt");
158+
should(result.projectContents.toString()).findString(`module.exports.default = "https://example.com/static/92849cf0-hello.txt";`);
159+
});
160+
}
144161
}

0 commit comments

Comments
 (0)