Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid the assumption of Buffer in browser envs (#3452)
* Avoid the assumption of Buffer in browser envs * add comment and one more check for findExistingAssetFileNameWithSource * remove lockfile * correct browser check * expand browser check * Make Uint8Array work in browser and add a test Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com> Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
- Loading branch information
1 parent
399bbf4
commit e9ece1d
Showing
21 changed files
with
235 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const Buffer = global.Buffer; | ||
|
||
module.exports = { | ||
description: | ||
'supports emitting assets as Uint8Arrays when Buffer is not available with deduplication', | ||
before() { | ||
delete global.Buffer; | ||
}, | ||
after() { | ||
global.Buffer = Buffer; | ||
}, | ||
options: { | ||
plugins: { | ||
resolveId(id) { | ||
if (id.startsWith('asset')) { | ||
return id; | ||
} | ||
}, | ||
load(id) { | ||
if (id.startsWith('asset')) { | ||
return `export default import.meta.ROLLUP_FILE_URL_${this.emitFile({ | ||
type: 'asset', | ||
source: Uint8Array.from(Array.from(id.slice(0, -1)).map(char => char.charCodeAt(0))) | ||
})};`; | ||
} | ||
} | ||
} | ||
} | ||
}; |
15 changes: 15 additions & 0 deletions
15
test/form/samples/emit-uint8array-no-buffer/_expected/amd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
var asset1a = new URL(require.toUrl('./assets/asset-dc5cb674'), document.baseURI).href; | ||
|
||
var asset1b = new URL(require.toUrl('./assets/asset-dc5cb674'), document.baseURI).href; | ||
|
||
var asset2a = new URL(require.toUrl('./assets/asset-52cbd095'), document.baseURI).href; | ||
|
||
var asset2b = new URL(require.toUrl('./assets/asset-52cbd095'), document.baseURI).href; | ||
|
||
var asset99a = new URL(require.toUrl('./assets/asset-c568a840'), document.baseURI).href; | ||
|
||
console.log(asset1a, asset1b, asset2a, asset2b, asset99a); | ||
|
||
}); |
1 change: 1 addition & 0 deletions
1
test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-52cbd095
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
asset2 |
1 change: 1 addition & 0 deletions
1
test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-c568a840
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
asset99 |
1 change: 1 addition & 0 deletions
1
test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-dc5cb674
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
asset1 |
13 changes: 13 additions & 0 deletions
13
test/form/samples/emit-uint8array-no-buffer/_expected/cjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
var asset1a = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-dc5cb674').href : new URL('assets/asset-dc5cb674', document.currentScript && document.currentScript.src || document.baseURI).href); | ||
|
||
var asset1b = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-dc5cb674').href : new URL('assets/asset-dc5cb674', document.currentScript && document.currentScript.src || document.baseURI).href); | ||
|
||
var asset2a = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-52cbd095').href : new URL('assets/asset-52cbd095', document.currentScript && document.currentScript.src || document.baseURI).href); | ||
|
||
var asset2b = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-52cbd095').href : new URL('assets/asset-52cbd095', document.currentScript && document.currentScript.src || document.baseURI).href); | ||
|
||
var asset99a = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-c568a840').href : new URL('assets/asset-c568a840', document.currentScript && document.currentScript.src || document.baseURI).href); | ||
|
||
console.log(asset1a, asset1b, asset2a, asset2b, asset99a); |
11 changes: 11 additions & 0 deletions
11
test/form/samples/emit-uint8array-no-buffer/_expected/es.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var asset1a = new URL('assets/asset-dc5cb674', import.meta.url).href; | ||
|
||
var asset1b = new URL('assets/asset-dc5cb674', import.meta.url).href; | ||
|
||
var asset2a = new URL('assets/asset-52cbd095', import.meta.url).href; | ||
|
||
var asset2b = new URL('assets/asset-52cbd095', import.meta.url).href; | ||
|
||
var asset99a = new URL('assets/asset-c568a840', import.meta.url).href; | ||
|
||
console.log(asset1a, asset1b, asset2a, asset2b, asset99a); |
16 changes: 16 additions & 0 deletions
16
test/form/samples/emit-uint8array-no-buffer/_expected/iife.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
var asset1a = new URL('assets/asset-dc5cb674', document.currentScript && document.currentScript.src || document.baseURI).href; | ||
|
||
var asset1b = new URL('assets/asset-dc5cb674', document.currentScript && document.currentScript.src || document.baseURI).href; | ||
|
||
var asset2a = new URL('assets/asset-52cbd095', document.currentScript && document.currentScript.src || document.baseURI).href; | ||
|
||
var asset2b = new URL('assets/asset-52cbd095', document.currentScript && document.currentScript.src || document.baseURI).href; | ||
|
||
var asset99a = new URL('assets/asset-c568a840', document.currentScript && document.currentScript.src || document.baseURI).href; | ||
|
||
console.log(asset1a, asset1b, asset2a, asset2b, asset99a); | ||
|
||
}()); |
Oops, something went wrong.