breaking: Remove dependency on streams polyfill (#149)

* Remove dependency on streams polyfill

* require node v16.7

* change test version

* only test ubuntu

* remove changelog
This commit is contained in:
Jimmy Wärting
2023-05-18 13:44:05 +02:00
committed by GitHub
parent 57e4daef36
commit a1a182e597
12 changed files with 65 additions and 231 deletions
+16 -22
View File
@@ -5,36 +5,29 @@ import { get } from 'node:https'
const fetch = url => new Promise(rs => get(url, rs))
const cache = new URL('./.cache/', import.meta.url)
/**
* @param {string} specifier
* @param {{
* conditions: !Array<string>,
* parentURL: !(string | undefined),
* }} context
* @param {Function} defaultResolve
* @returns {Promise<{ url: string }>}
*/
export async function resolve (specifier, context, defaultResolve) {
const { parentURL = null } = context
export function resolve(specifier, context, nextResolve) {
const { parentURL = null } = context;
// Normally Node.js would error on specifiers starting with 'https://', so
// this hook intercepts them and converts them into absolute URLs to be
// passed along to the later hooks below.
if (specifier.startsWith('https://')) {
return {
url: specifier
}
shortCircuit: true,
url: specifier,
};
} else if (parentURL && parentURL.startsWith('https://')) {
return {
url: new URL(specifier, parentURL).href
}
shortCircuit: true,
url: new URL(specifier, parentURL).href,
};
}
// Let Node.js handle all other specifiers.
return defaultResolve(specifier, context, defaultResolve)
return nextResolve(specifier);
}
export async function load (url, context, defaultLoad) {
export async function load(url, context, nextLoad) {
// For JavaScript to be loaded over the network, we need to fetch and
// return it.
if (url.startsWith('https://')) {
@@ -52,14 +45,15 @@ export async function load (url, context, defaultLoad) {
fs.writeFileSync(cachedFile, data)
}
// This example assumes all network-provided JavaScript is ES module
// code.
return {
// This example assumes all network-provided JavaScript is ES module
// code.
format: 'module',
source: data
shortCircuit: true,
source: data,
}
}
// Let Node.js handle all other URLs.
return defaultLoad(url, context, defaultLoad)
}
return nextLoad(url);
}
-5
View File
@@ -63,11 +63,6 @@ test(() => {
assert_equals(blobFromSync, syncBlob)
}, 'default export is named exported blobFromSync')
promise_test(async () => {
const { Blob, default: def } = await import('../index.js')
assert_equals(Blob, def)
}, 'Can use named import - as well as default')
// This was necessary to avoid large ArrayBuffer clones (slice)
promise_test(async t => {
const buf = new Uint8Array(65590)
+5 -2
View File
@@ -22,7 +22,7 @@ function test_blob (fn, expectations) {
const blob = fn()
assert_true(blob instanceof Blob)
assert_false(blob instanceof File)
assert_equals(blob.type.toLowerCase(), type)
assert_equals(blob.type.toLowerCase(), type.toLowerCase())
assert_equals(await blob.text(), expected)
t.done()
})
@@ -140,4 +140,7 @@ import('https://wpt.live/FileAPI/blob/Blob-stream.any.js')
import('https://wpt.live/FileAPI/blob/Blob-text.any.js')
import('./own-misc-test.js')
hasFailed && process.exit(1)
if (hasFailed) {
console.log('Tests failed')
process.exit(1)
}