From fd81a98c2be908585b9e2a27281e31d0136cdc9f Mon Sep 17 00:00:00 2001 From: Brendan Baldwin Date: Thu, 21 Jun 2018 20:23:09 -0700 Subject: [PATCH] Convert 'new Buffer(' to 'Buffer.from(' as constructor is deprecated in Node 10 --- packages/build/src/base-tag-updater.ts | 2 +- packages/build/src/bundle.ts | 2 +- .../build/src/custom-elements-es5-adapter.ts | 2 +- packages/build/src/html-splitter.ts | 6 ++-- packages/build/src/inject-babel-helpers.ts | 2 +- packages/build/src/optimize-streams.ts | 2 +- packages/build/src/prefetch-links.ts | 2 +- packages/build/src/push-manifest.ts | 2 +- packages/build/src/service-worker.ts | 2 +- packages/build/src/test/bundle_test.ts | 4 +-- packages/build/src/test/html-splitter_test.ts | 2 +- .../esm-amd-loader/test/package-lock.json | 36 +++++++++---------- .../polyserve/src/transform-middleware.ts | 4 +-- 13 files changed, 34 insertions(+), 34 deletions(-) diff --git a/packages/build/src/base-tag-updater.ts b/packages/build/src/base-tag-updater.ts index 67e91bbd6..8be70d595 100644 --- a/packages/build/src/base-tag-updater.ts +++ b/packages/build/src/base-tag-updater.ts @@ -48,7 +48,7 @@ export class BaseTagUpdater extends AsyncTransformStream { dom5.setAttribute(base, 'href', this.newHref); dom5.removeFakeRootElements(parsed); const updatedFile = file.clone(); - updatedFile.contents = new Buffer(parse5.serialize(parsed), 'utf-8'); + updatedFile.contents = Buffer.from(parse5.serialize(parsed), 'utf-8'); yield updatedFile; } } diff --git a/packages/build/src/bundle.ts b/packages/build/src/bundle.ts index 82d35a73d..92fb3d19a 100644 --- a/packages/build/src/bundle.ts +++ b/packages/build/src/bundle.ts @@ -111,7 +111,7 @@ export class BuildBundler extends AsyncTransformStream { path: pathFromUrl( this.config.root as LocalFsPath, this._bundler.analyzer.urlResolver.relative(url)), - contents: new Buffer(document.content), + contents: Buffer.from(document.content), })); } } diff --git a/packages/build/src/custom-elements-es5-adapter.ts b/packages/build/src/custom-elements-es5-adapter.ts index 05972df55..3e0aee593 100644 --- a/packages/build/src/custom-elements-es5-adapter.ts +++ b/packages/build/src/custom-elements-es5-adapter.ts @@ -39,7 +39,7 @@ export class CustomElementsEs5AdapterInjector extends yield file; } else { const updatedFile = file.clone(); - updatedFile.contents = new Buffer(updatedContents, 'utf-8'); + updatedFile.contents = Buffer.from(updatedContents, 'utf-8'); yield updatedFile; } } diff --git a/packages/build/src/html-splitter.ts b/packages/build/src/html-splitter.ts index 0ffb3186d..c79820e65 100644 --- a/packages/build/src/html-splitter.ts +++ b/packages/build/src/html-splitter.ts @@ -196,7 +196,7 @@ class HtmlSplitTransform extends AsyncTransformStream { cwd: file.cwd, base: file.base, path: childPath, - contents: new Buffer(source), + contents: Buffer.from(source), }); scriptFile.fromHtmlSplitter = true; scriptFile.isModule = typeAttribute === 'module'; @@ -210,7 +210,7 @@ class HtmlSplitTransform extends AsyncTransformStream { cwd: file.cwd, base: file.base, path: filePath, - contents: new Buffer(splitContents), + contents: Buffer.from(splitContents), }); yield newFile; } @@ -291,7 +291,7 @@ class HtmlRejoinTransform extends AsyncTransformStream { cwd: file.cwd, base: file.base, path: filePath, - contents: new Buffer(joinedContents), + contents: Buffer.from(joinedContents), }); } } diff --git a/packages/build/src/inject-babel-helpers.ts b/packages/build/src/inject-babel-helpers.ts index 3fddee1ec..7a464eea5 100644 --- a/packages/build/src/inject-babel-helpers.ts +++ b/packages/build/src/inject-babel-helpers.ts @@ -39,7 +39,7 @@ export class BabelHelpersInjector extends AsyncTransformStream { const contents = await getFileContents(file); const transformed = htmlTransform(contents, {injectBabelHelpers: 'full'}); const newFile = file.clone(); - newFile.contents = new Buffer(transformed, 'utf-8'); + newFile.contents = Buffer.from(transformed, 'utf-8'); return newFile; } } diff --git a/packages/build/src/optimize-streams.ts b/packages/build/src/optimize-streams.ts index 52d1e8aec..804817a90 100644 --- a/packages/build/src/optimize-streams.ts +++ b/packages/build/src/optimize-streams.ts @@ -94,7 +94,7 @@ export class GenericOptimizeTransform extends Transform { try { let contents = file.contents.toString(); contents = this.optimizer(contents, file); - file.contents = new Buffer(contents); + file.contents = Buffer.from(contents); } catch (error) { logger.warn( `${this.optimizerName}: Unable to optimize ${file.path}`, diff --git a/packages/build/src/prefetch-links.ts b/packages/build/src/prefetch-links.ts index 5ce5ea9e2..ea70cad0f 100644 --- a/packages/build/src/prefetch-links.ts +++ b/packages/build/src/prefetch-links.ts @@ -111,7 +111,7 @@ export class AddPrefetchLinks extends AsyncTransformStream { const filePath = pathFromUrl( this._config.root as LocalFsPath, this._analyzer.urlResolver.relative(documentUrl)); - yield new File({contents: new Buffer(html, 'utf-8'), path: filePath}); + yield new File({contents: Buffer.from(html, 'utf-8'), path: filePath}); } } } diff --git a/packages/build/src/push-manifest.ts b/packages/build/src/push-manifest.ts index 0e5f4cbb8..e92159e44 100644 --- a/packages/build/src/push-manifest.ts +++ b/packages/build/src/push-manifest.ts @@ -207,7 +207,7 @@ export class AddPushManifest extends AsyncTransformStream { // Push the new push manifest into the stream. yield new File({ path: this.outPath, - contents: new Buffer(pushManifestContents), + contents: Buffer.from(pushManifestContents), }); } diff --git a/packages/build/src/service-worker.ts b/packages/build/src/service-worker.ts index 24b8724b2..2e7138a2b 100644 --- a/packages/build/src/service-worker.ts +++ b/packages/build/src/service-worker.ts @@ -194,7 +194,7 @@ export async function generateServiceWorker(options: AddServiceWorkerOptions): // and parentheses. To ensure the output is consistent across // versions, we will correctively insert missing space here. fileContents = fileContents.replace(/\bfunction\(/g, 'function ('); - resolve(new Buffer(fileContents)); + resolve(Buffer.from(fileContents)); } }); })); diff --git a/packages/build/src/test/bundle_test.ts b/packages/build/src/test/bundle_test.ts index 20daa3953..0f0b32c0d 100644 --- a/packages/build/src/test/bundle_test.ts +++ b/packages/build/src/test/bundle_test.ts @@ -122,10 +122,10 @@ suite('BuildBundler', () => { const addHeaders = new FileTransform((stream, file) => { if (path.extname(file.path) === '.html') { file.contents = - new Buffer(`${file.contents}`); + Buffer.from(`${file.contents}`); } else if (path.extname(file.path).match(/^\.(js|css)$/)) { file.contents = - new Buffer(`/* ${path.basename(file.path)} */${file.contents}`); + Buffer.from(`/* ${path.basename(file.path)} */${file.contents}`); } stream.push(file); }); diff --git a/packages/build/src/test/html-splitter_test.ts b/packages/build/src/test/html-splitter_test.ts index 673abfcbe..555166eb2 100644 --- a/packages/build/src/test/html-splitter_test.ts +++ b/packages/build/src/test/html-splitter_test.ts @@ -105,7 +105,7 @@ suite('HtmlSplitter', () => { cwd: root, base: root, path: filepath, - contents: new Buffer(source), + contents: Buffer.from(source), }); sourceStream.pipe(htmlSplitter.split()) diff --git a/packages/esm-amd-loader/test/package-lock.json b/packages/esm-amd-loader/test/package-lock.json index 935acde63..0e2dd66ab 100644 --- a/packages/esm-amd-loader/test/package-lock.json +++ b/packages/esm-amd-loader/test/package-lock.json @@ -11,9 +11,9 @@ "dev": true }, "@types/mocha": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.2.tgz", - "integrity": "sha512-tfg9rh2qQhBW6SBqpvfqTgU6lHWGhQURoTrn7NeDF+CEkO9JGYbkzU23EXu6p3bnvDxLeeSX8ohAA23urvWeNw==", + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.3.tgz", + "integrity": "sha512-C1wVVr7xhKu6c3Mb27dFzNYR05qvHwgtpN+JOYTGc1pKA7dCEDDYpscn7kul+bCUwa3NoGDbzI1pdznSOa397w==", "dev": true }, "@webcomponents/webcomponentsjs": { @@ -40,7 +40,7 @@ "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "requires": { - "balanced-match": "1.0.0", + "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, @@ -50,9 +50,9 @@ "integrity": "sha512-x90Hac4ERacGDcZSvHKK58Ga0STuMD+Doi5g0iG2zf7wlJef5Huvhs/3BvMRFxwRYyYSdl6mpQNrtfMxE8MQzw==", "dev": true, "requires": { - "async": "1.5.2", - "glob": "7.1.2", - "resolve": "1.8.1" + "async": "^1.5.2", + "glob": "^7.0.0", + "resolve": "^1.1.6" } }, "concat-map": { @@ -73,12 +73,12 @@ "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", "dev": true, "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" } }, "inflight": { @@ -87,8 +87,8 @@ "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "dev": true, "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" + "once": "^1.3.0", + "wrappy": "1" } }, "inherits": { @@ -103,7 +103,7 @@ "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "requires": { - "brace-expansion": "1.1.11" + "brace-expansion": "^1.1.7" } }, "once": { @@ -112,7 +112,7 @@ "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { - "wrappy": "1.0.2" + "wrappy": "1" } }, "path-is-absolute": { @@ -133,7 +133,7 @@ "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", "dev": true, "requires": { - "path-parse": "1.0.5" + "path-parse": "^1.0.5" } }, "wrappy": { diff --git a/packages/polyserve/src/transform-middleware.ts b/packages/polyserve/src/transform-middleware.ts index b742aab6d..c789ae41b 100644 --- a/packages/polyserve/src/transform-middleware.ts +++ b/packages/polyserve/src/transform-middleware.ts @@ -45,7 +45,7 @@ export function transformResponse(transformer: ResponseTransformer): if (shouldTransform()) { const buffer = (typeof chunk === 'string') ? - new Buffer(chunk, cbOrEncoding as string) : + Buffer.from(chunk, cbOrEncoding as string) : chunk; chunks.push(buffer); return true; @@ -68,7 +68,7 @@ export function transformResponse(transformer: ResponseTransformer): if (Buffer.isBuffer(cbOrChunk)) { chunks.push(cbOrChunk); } else if (typeof cbOrChunk === 'string') { - chunks.push(new Buffer(cbOrChunk, cbOrEncoding as string)); + chunks.push(Buffer.from(cbOrChunk, cbOrEncoding as string)); } const body = Buffer.concat(chunks).toString('utf8'); let newBody = body;