Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't require stream package in codebase #520

Merged
merged 4 commits into from Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/browsers.yml
Expand Up @@ -38,5 +38,7 @@ jobs:
run: ./node_modules/.bin/playwright install ${{ fromJSON('{"chrome":"chromium","edge":"msedge","firefox":"firefox","safari":"webkit"}')[matrix.browser] }}
- name: Bundle code
run: npm run test:prepare ${{ matrix.bundler }}
- name: Bundle readable-stream code with readable-stream specific bundlers
run: npm run test:readable-stream-only ${{ matrix.bundler }}
- name: Run Tests on Browsers
run: npm run test:browsers ${{ matrix.browser }} ${{ matrix.bundler }}
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,5 @@ coverage/
node_modules/
node-*.tar.gz
package-lock.json
tmp/
tmp/
readable-stream-test/dist/
4 changes: 3 additions & 1 deletion build/replacements.mjs
Expand Up @@ -236,6 +236,8 @@ const readmeInfo = ['(This package is a mirror of the streams implementations in

const readmeLink = ['(\\[Node.js website\\]\\(https://nodejs.org/dist/v)(\\d+.\\d+.\\d+)', '$1$2']

const streamRequire = [ "require\\('stream'\\)", "require('../../lib/stream.js')" ]

export const replacements = {
'lib/_stream.+': [legacyStreamsRequireStream],
'lib/internal/streams/duplexify.+': [
Expand Down Expand Up @@ -288,7 +290,7 @@ export const replacements = {
streamIndexRequireUtil,
streamIndexRequireInternal
],
'lib/stream/.+': [streamsRequireErrors, streamsRequirePrimordials, streamsRequireInternal],
'lib/stream/.+': [streamsRequireErrors, streamsRequirePrimordials, streamsRequireInternal, streamRequire],
'test/common/index.js': [testCommonKnownGlobals],
'test/parallel/.+': [
testParallelIncludeTap,
Expand Down
2 changes: 1 addition & 1 deletion lib/stream/promises.js
Expand Up @@ -4,7 +4,7 @@ const { ArrayPrototypePop, Promise } = require('../ours/primordials')
const { isIterable, isNodeStream, isWebStream } = require('../internal/streams/utils')
const { pipelineImpl: pl } = require('../internal/streams/pipeline')
const { finished } = require('../internal/streams/end-of-stream')
require('stream')
require('../../lib/stream.js')
function pipeline(...streams) {
return new Promise((resolve, reject) => {
let signal
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -39,6 +39,7 @@
"test:prepare": "node test/browser/runner-prepare.mjs",
"test:browsers": "node test/browser/runner-browser.mjs",
"test:bundlers": "node test/browser/runner-node.mjs",
"test:readable-stream-only": "node readable-stream-test/runner-prepare.mjs",
"coverage": "c8 -c ./c8.json tap --rcfile=./tap.yml test/parallel/test-*.js test/ours/test-*.js",
"format": "prettier -w src lib test",
"lint": "eslint src"
Expand Down
3 changes: 3 additions & 0 deletions readable-stream-test/import.js
@@ -0,0 +1,3 @@
import * as all from '../lib/ours'
import * as allBrowser from '../lib/ours/browser'
import * as allRoot from '../lib/ours'
77 changes: 77 additions & 0 deletions readable-stream-test/runner-prepare.mjs
@@ -0,0 +1,77 @@
import { exec } from 'child_process'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See line 27 (note this is a copy /paste of a subset of the code in the nodejs fixtures)

import util from '../lib/ours/util.js'

function info(message) {
console.log(`\x1b[34m[INFO]\x1b[0m ${message}`)
}

function error(message) {
console.log(`\x1b[31m[INFO]\x1b[0m ${message}`)
}

async function run(command) {
info(`Executing \x1b[33m${command}\x1b[0m ...`)
const { promise, reject, resolve } = util.createDeferredPromise()

let hasOutput = false
function logOutput(chunk) {
if (!hasOutput) {
hasOutput = true
console.log('')
}

console.log(chunk.toString('utf-8').trim().replace(/^/gm, ' '))
}

try {
const process = exec(command, { stdio: 'pipe' }, (error) => {
if (error) {
return reject(error)
}

resolve(error)
})

process.stdout.on('data', logOutput)
process.stderr.on('data', logOutput)
await promise

if (hasOutput) {
console.log('')
}
} catch (e) {
if (hasOutput) {
console.log('')
}

error(`Command failed with status code ${e.code}.`)
process.exit(1)
}
}

async function main() {
const validBundlers = ['browserify', 'esbuild', 'rollup', 'webpack']
const bundler = process.argv[2] || process.env.BUNDLER

if (!validBundlers.includes(bundler)) {
error(`Usage: node await runner-prepare.mjs [${validBundlers.join('|')}]`)
error('You can also use the BUNDLER environment variable.')
process.exit(1)
}

switch (bundler) {
case 'browserify':
break
case 'esbuild':
break
case 'rollup':
break
case 'webpack':
await run('webpack -c readable-stream-test/webpack.config.mjs')
}
}

main().catch((e) => {
error(e)
process.exit(1)
})
13 changes: 13 additions & 0 deletions readable-stream-test/webpack.config.mjs
@@ -0,0 +1,13 @@
import { resolve } from 'path'
import { fileURLToPath } from 'url'

const rootDir = resolve(fileURLToPath(new URL('.', import.meta.url)), '../')

export default {
mode: 'development',
entry: './readable-stream-test/import.js',
output: {
path: resolve(rootDir, 'readable-stream-test', 'dist'),
filename: 'import.js'
}
}