Skip to content

Commit

Permalink
Convert 'new Buffer(' to 'Buffer.from(' as constructor is deprecated …
Browse files Browse the repository at this point in the history
…in Node 10
  • Loading branch information
usergenic committed Jun 22, 2018
1 parent 4ac1631 commit fd81a98
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/build/src/base-tag-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class BaseTagUpdater extends AsyncTransformStream<File, File> {
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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class BuildBundler extends AsyncTransformStream<File, File> {
path: pathFromUrl(
this.config.root as LocalFsPath,
this._bundler.analyzer.urlResolver.relative(url)),
contents: new Buffer(document.content),
contents: Buffer.from(document.content),
}));
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/custom-elements-es5-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/build/src/html-splitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class HtmlSplitTransform extends AsyncTransformStream<File, File> {
cwd: file.cwd,
base: file.base,
path: childPath,
contents: new Buffer(source),
contents: Buffer.from(source),
});
scriptFile.fromHtmlSplitter = true;
scriptFile.isModule = typeAttribute === 'module';
Expand All @@ -210,7 +210,7 @@ class HtmlSplitTransform extends AsyncTransformStream<File, File> {
cwd: file.cwd,
base: file.base,
path: filePath,
contents: new Buffer(splitContents),
contents: Buffer.from(splitContents),
});
yield newFile;
}
Expand Down Expand Up @@ -291,7 +291,7 @@ class HtmlRejoinTransform extends AsyncTransformStream<File, File> {
cwd: file.cwd,
base: file.base,
path: filePath,
contents: new Buffer(joinedContents),
contents: Buffer.from(joinedContents),
});
}
}
2 changes: 1 addition & 1 deletion packages/build/src/inject-babel-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class BabelHelpersInjector extends AsyncTransformStream<File, File> {
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;
}
}
2 changes: 1 addition & 1 deletion packages/build/src/optimize-streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/prefetch-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class AddPrefetchLinks extends AsyncTransformStream<File, File> {
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});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/push-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class AddPushManifest extends AsyncTransformStream<File, File> {
// Push the new push manifest into the stream.
yield new File({
path: this.outPath,
contents: new Buffer(pushManifestContents),
contents: Buffer.from(pushManifestContents),
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});
}));
Expand Down
4 changes: 2 additions & 2 deletions packages/build/src/test/bundle_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ suite('BuildBundler', () => {
const addHeaders = new FileTransform((stream, file) => {
if (path.extname(file.path) === '.html') {
file.contents =
new Buffer(`<!-- ${path.basename(file.path)} -->${file.contents}`);
Buffer.from(`<!-- ${path.basename(file.path)} -->${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);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/test/html-splitter_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ suite('HtmlSplitter', () => {
cwd: root,
base: root,
path: filepath,
contents: new Buffer(source),
contents: Buffer.from(source),
});

sourceStream.pipe(htmlSplitter.split())
Expand Down
36 changes: 18 additions & 18 deletions packages/esm-amd-loader/test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/polyserve/src/transform-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit fd81a98

Please sign in to comment.