Skip to content

Commit 80a223b

Browse files
authored
Fix a parcel build warning; Bump version to 0.2.5 (tensorflow#149)
The parcel issue is described at: parcel-bundler/parcel#2363 parcel doesn't like `fs.readFileSync`. This PR uses `fs.readFile` to work around that. BUG
1 parent 13c6a56 commit 80a223b

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

speech-commands/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tensorflow-models/speech-commands",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"description": "Speech-command recognizer in TensorFlow.js",
55
"main": "dist/index.js",
66
"unpkg": "dist/speech-commands.min.js",

speech-commands/src/browser_fft_utils.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,27 @@ import * as tf from '@tensorflow/tfjs';
1919

2020
export async function loadMetadataJson(url: string):
2121
Promise<{words: string[]}> {
22-
const HTTP_SCHEME = 'http://';
23-
const HTTPS_SCHEME = 'https://';
24-
const FILE_SCHEME = 'file://';
25-
if (url.indexOf(HTTP_SCHEME) === 0 || url.indexOf(HTTPS_SCHEME) === 0) {
26-
return await (await fetch(url)).json();
27-
} else if (url.indexOf(FILE_SCHEME) === 0) {
28-
// tslint:disable-next-line:no-require-imports
29-
const fs = require('fs');
30-
const content = JSON.parse(
31-
fs.readFileSync(url.slice(FILE_SCHEME.length), {encoding: 'utf-8'}));
32-
return content;
33-
} else {
34-
throw new Error(
35-
`Unsupported URL scheme in metadata URL: ${url}. ` +
36-
`Supported schemes are: http://, https://, and ` +
37-
`(node.js-only) file://`);
38-
}
22+
return new Promise((resolve, reject) => {
23+
const HTTP_SCHEME = 'http://';
24+
const HTTPS_SCHEME = 'https://';
25+
const FILE_SCHEME = 'file://';
26+
if (url.indexOf(HTTP_SCHEME) === 0 || url.indexOf(HTTPS_SCHEME) === 0) {
27+
fetch(url).then(response => {
28+
response.json().then(parsed => resolve(parsed));
29+
});
30+
} else if (url.indexOf(FILE_SCHEME) === 0) {
31+
// tslint:disable-next-line:no-require-imports
32+
const fs = require('fs');
33+
fs.readFile(
34+
url.slice(FILE_SCHEME.length), {encoding: 'utf-8'},
35+
(err: Error, data: string) => resolve(JSON.parse(data)));
36+
} else {
37+
reject(new Error(
38+
`Unsupported URL scheme in metadata URL: ${url}. ` +
39+
`Supported schemes are: http://, https://, and ` +
40+
`(node.js-only) file://`));
41+
}
42+
}) as Promise<{words: string[]}>;
3943
}
4044

4145
let EPSILON: number = null;

speech-commands/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/** @license See the LICENSE file. */
22
// This code is auto-generated, do not modify this file!
3-
const version = '0.2.4';
3+
const version = '0.2.5';
44
export {version};

0 commit comments

Comments
 (0)