Skip to content

Commit 4f9f9cc

Browse files
committed
🐛 fix updateURL resolution
Fix #82
1 parent aa441fd commit 4f9f9cc

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

lib/features/resolve-base-urls.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ export class ResolveBaseURLs extends Feature<ResolveBaseURLsOptions> {
3232
if (headers.updateURL === undefined) {
3333
headers = {
3434
...headers,
35-
updateURL: metajs
36-
? new URL(metajsFile, updateBaseURL).toString()
37-
: updateBaseURL !== undefined
38-
? new URL(userjsFile, updateBaseURL).toString()
39-
: headers.downloadURL,
35+
updateURL: new URL(
36+
metajs ? metajsFile : userjsFile,
37+
updateBaseURL ?? downloadBaseURL,
38+
).toString(),
4039
};
4140
}
4241

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { GlobalFixtures } from '../fixtures';
22

33
export class Fixtures extends GlobalFixtures {
4-
public static readonly downloadURL =
4+
public static readonly downloadURLWithUserjs =
55
'http://download.example.com/output.user.js';
66

7-
public static readonly updateURLByMetajs =
7+
public static readonly downloadURLWithMetajs =
8+
'http://download.example.com/output.meta.js';
9+
10+
public static readonly updateURLWithMetajs =
811
'http://update.example.com/output.meta.js';
912

10-
public static readonly updateURLByUserjs =
13+
public static readonly updateURLWithUserjs =
1114
'http://update.example.com/output.user.js';
1215
}

test/integration/resolve-base-urls/index.test.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('resolve base urls', () => {
1212
const findDownloadURL = findTags.bind(
1313
undefined,
1414
'downloadURL',
15-
Fixtures.downloadURL,
15+
Fixtures.downloadURLWithUserjs,
1616
);
1717

1818
beforeEach(async () => {
@@ -26,7 +26,7 @@ describe('resolve base urls', () => {
2626
const findUpdateURLByMetajs = findTags.bind(
2727
undefined,
2828
'updateURL',
29-
Fixtures.updateURLByMetajs,
29+
Fixtures.updateURLWithMetajs,
3030
);
3131

3232
const output = await compile(input, {
@@ -53,11 +53,11 @@ describe('resolve base urls', () => {
5353
expect(findUpdateURLByMetajs(metaJs)).toHaveLength(1);
5454
});
5555

56-
it('should resolve updateURL by userjs', async () => {
56+
it('should resolve updateURL with updateBaseURL and userjs', async () => {
5757
const findUpdateURLByUserjs = findTags.bind(
5858
undefined,
5959
'updateURL',
60-
Fixtures.updateURLByUserjs,
60+
Fixtures.updateURLWithUserjs,
6161
);
6262

6363
const output = await compile(input, {
@@ -79,11 +79,11 @@ describe('resolve base urls', () => {
7979
expect(findUpdateURLByUserjs(userJs)).toHaveLength(1);
8080
});
8181

82-
it('should resolve updateURL by downloadURL', async () => {
82+
it('should resolve updateURL by downloadBaseURL and userjs', async () => {
8383
const findUpdateURLByDownloadURL = findTags.bind(
8484
undefined,
8585
'updateURL',
86-
Fixtures.downloadURL,
86+
Fixtures.downloadURLWithUserjs,
8787
);
8888

8989
const output = await compile(input, {
@@ -103,4 +103,29 @@ describe('resolve base urls', () => {
103103
expect(findDownloadURL(userJs)).toHaveLength(1);
104104
expect(findUpdateURLByDownloadURL(userJs)).toHaveLength(1);
105105
});
106+
107+
it('should resolve updateURL by downloadBaseURL and metajs', async () => {
108+
const findUpdateURLByDownloadURL = findTags.bind(
109+
undefined,
110+
'updateURL',
111+
Fixtures.downloadURLWithMetajs,
112+
);
113+
114+
const output = await compile(input, {
115+
...Fixtures.webpackConfig,
116+
plugins: [
117+
new UserscriptPlugin({
118+
downloadBaseURL: new URL('http://download.example.com'),
119+
metajs: true,
120+
}),
121+
],
122+
});
123+
124+
const userJs = output
125+
.readFileSync('/dist/output.user.js')
126+
.toString('utf-8');
127+
128+
expect(findDownloadURL(userJs)).toHaveLength(1);
129+
expect(findUpdateURLByDownloadURL(userJs)).toHaveLength(1);
130+
});
106131
});

0 commit comments

Comments
 (0)