mirror of https://github.com/status-im/metro.git
change `isPolyfill` to `type = 'module' | 'script'`
Summary: When building, we will process modules in a special way, *not* polyfillys. We will also add more types of (virtual) files that are not modules. That’s why a “type” property makes more sense. Reviewed By: cpojer Differential Revision: D4244583 fbshipit-source-id: 92a0b4a0a2026d0b97ba88034483a6ce4e0c1ebb
This commit is contained in:
parent
ee607f8ecf
commit
269d1e10fa
|
@ -50,7 +50,7 @@ type LoadQueue =
|
||||||
Async$Queue<{id: string, parent: string}, Callback<File, Array<string>>>;
|
Async$Queue<{id: string, parent: string}, Callback<File, Array<string>>>;
|
||||||
|
|
||||||
const createParentModule =
|
const createParentModule =
|
||||||
() => ({file: {code: '', isPolyfill: false, path: ''}, dependencies: []});
|
() => ({file: {code: '', type: 'script', path: ''}, dependencies: []});
|
||||||
|
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
const NO_OPTIONS = {};
|
const NO_OPTIONS = {};
|
||||||
|
|
|
@ -40,11 +40,13 @@ type Dependency = {|
|
||||||
|
|
||||||
export type File = {|
|
export type File = {|
|
||||||
code: string,
|
code: string,
|
||||||
isPolyfill: boolean,
|
|
||||||
map?: ?Object,
|
map?: ?Object,
|
||||||
path: string,
|
path: string,
|
||||||
|
type: FileTypes,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
type FileTypes = 'module' | 'script';
|
||||||
|
|
||||||
export type Module = {|
|
export type Module = {|
|
||||||
dependencies: Array<Dependency>,
|
dependencies: Array<Dependency>,
|
||||||
file: File,
|
file: File,
|
||||||
|
@ -82,9 +84,9 @@ export type TransformedFile = {
|
||||||
code: string,
|
code: string,
|
||||||
file: string,
|
file: string,
|
||||||
hasteID: ?string,
|
hasteID: ?string,
|
||||||
isPolyfill: boolean,
|
|
||||||
package?: PackageData,
|
package?: PackageData,
|
||||||
transformed: {[variant: string]: TransformResult},
|
transformed: {[variant: string]: TransformResult},
|
||||||
|
type: FileTypes,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PackageData = {|
|
export type PackageData = {|
|
||||||
|
|
|
@ -62,16 +62,16 @@ describe('transforming JS modules:', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets `isPolyfill` to `false` by default', done => {
|
it('sets `type` to `"module"` by default', done => {
|
||||||
transformModule(sourceCode, options(), (error, result) => {
|
transformModule(sourceCode, options(), (error, result) => {
|
||||||
expect(result).toEqual(objectContaining({isPolyfill: false}));
|
expect(result).toEqual(objectContaining({type: 'module'}));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets `isPolyfill` to `true` if the input is a polyfill', done => {
|
it('sets `type` to `"script"` if the input is a polyfill', done => {
|
||||||
transformModule(sourceCode, {...options(), polyfill: true}, (error, result) => {
|
transformModule(sourceCode, {...options(), polyfill: true}, (error, result) => {
|
||||||
expect(result).toEqual(objectContaining({isPolyfill: true}));
|
expect(result).toEqual(objectContaining({type: 'script'}));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -75,9 +75,9 @@ function transformModule(
|
||||||
callback(null, {
|
callback(null, {
|
||||||
code,
|
code,
|
||||||
file: filename,
|
file: filename,
|
||||||
isPolyfill: !!options.polyfill,
|
|
||||||
hasteID: annotations.providesModule || annotations.provide || null,
|
hasteID: annotations.providesModule || annotations.provide || null,
|
||||||
transformed,
|
transformed,
|
||||||
|
type: options.polyfill ? 'script' : 'module',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,8 @@ function transformJSON(json, options, callback) {
|
||||||
code: json,
|
code: json,
|
||||||
file: filename,
|
file: filename,
|
||||||
hasteID: value.name,
|
hasteID: value.name,
|
||||||
isPolyfill: false,
|
|
||||||
transformed,
|
transformed,
|
||||||
|
type: 'module',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (basename(filename) === 'package.json') {
|
if (basename(filename) === 'package.json') {
|
||||||
|
|
Loading…
Reference in New Issue