Skip to content

Commit

Permalink
moved the logic to replacements.mjs
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Bhandari <rishabhbhandari6@gmail.com>
  • Loading branch information
RishabhKodes committed Feb 27, 2023
1 parent de43dd6 commit 651395a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
13 changes: 3 additions & 10 deletions build/build.mjs
Expand Up @@ -12,7 +12,7 @@ import prettierConfig from '../prettier.config.cjs'
import { aliases, skippedSources, sources } from './files.mjs'
import { footers } from './footers.mjs'
import { headers } from './headers.mjs'
import { replacements } from './replacements.mjs'
import { replacements, removeObsoleteReadableMethods } from './replacements.mjs'

const baseMatcher = /^(?:lib|test)/
const strictMatcher = /^(['"']use strict.+)/
Expand Down Expand Up @@ -173,15 +173,8 @@ async function main() {
await rm('test', { recursive: true, force: true })

// remove obsolete methods from readable-stream
const methodNameToRemove = ['fromWeb', 'toWeb']
const readableStreamPath = resolve(__dirname, '../lib/internal/streams/readable.js')
let readableStreamContent = await readFile(readableStreamPath, 'utf-8')

for (const method of methodNameToRemove) {
const regex = new RegExp(`Readable.+${method} = function\\s\\s*\\([^)]*\\)\\s*{[^}]*}`, 'g')
readableStreamContent = readableStreamContent.replace(regex, '')
writeFileSync(readableStreamPath, readableStreamContent, 'utf8')
}
const methodNamesToRemove = ['fromWeb', 'toWeb']
await removeObsoleteReadableMethods(methodNamesToRemove)

// Download or open the tar file
let tarFile
Expand Down
15 changes: 15 additions & 0 deletions build/replacements.mjs
@@ -1,3 +1,7 @@
import { resolve } from 'node:path'
import { writeFileSync } from 'node:fs'
import { readFile } from 'node:fs/promises'

const legacyStreamsRequireStream = ["require\\('stream'\\)", "require('./stream')"]

const internalStreamsBufferPolyfill = [
Expand Down Expand Up @@ -152,6 +156,17 @@ const testParallelIncludeTap = [

const testParallelImportStreamInMjs = [" from 'stream';", "from '../../lib/ours/index.js';"]

export const removeObsoleteReadableMethods = async function(methodNames) {
const readableStreamPath = resolve(__dirname, '../lib/internal/streams/readable.js')
let readableStreamContent = await readFile(readableStreamPath, 'utf-8')

for (const method of methodNames) {
const regex = new RegExp(`Readable.+${method} = function\\s\\s*\\([^)]*\\)\\s*{[^}]*}`, 'g')
readableStreamContent = readableStreamContent.replace(regex, '')
writeFileSync(readableStreamPath, readableStreamContent, 'utf8')
}
}

const testParallelImportTapInMjs = ["(from 'assert';)", "$1\nimport tap from 'tap';"]

const testParallelDuplexFromBlob = [
Expand Down

0 comments on commit 651395a

Please sign in to comment.