Re-use pkg-lib for runtime plugin compilation
Summary: Re-use the same function for plugin building both at publishing time by "flipper-pkg" and in runtime by Flipper itself. Reviewed By: jknoxville Differential Revision: D21129685 fbshipit-source-id: b7bff6737310352d28a14223128f127ac4d2eebf
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ca2d04a5da
commit
8a7470556e
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {transform} from '@babel/core';
|
||||
import electronRequiresMainPlugin = require('../electron-requires-main');
|
||||
|
||||
const babelOptions = {
|
||||
ast: true,
|
||||
plugins: [electronRequiresMainPlugin],
|
||||
filename: 'index.js',
|
||||
};
|
||||
|
||||
const testCase1 = "const module = require('module');";
|
||||
test(testCase1, () => {
|
||||
const src = testCase1;
|
||||
const code = transform(src, babelOptions)!.code;
|
||||
expect(code).toMatchInlineSnapshot(
|
||||
`"const module = electronRequire('module');"`,
|
||||
);
|
||||
});
|
||||
|
||||
const testCase2 = "const module = require('./module');";
|
||||
test(testCase2, () => {
|
||||
const src = testCase2;
|
||||
const code = transform(src, babelOptions)!.code;
|
||||
expect(code).toMatchInlineSnapshot(`"const module = require('./module');"`);
|
||||
});
|
||||
|
||||
const testCase3 = "const module = require('../module');";
|
||||
test(testCase3, () => {
|
||||
const src = testCase3;
|
||||
const code = transform(src, babelOptions)!.code;
|
||||
expect(code).toMatchInlineSnapshot(`"const module = require('../module');"`);
|
||||
});
|
||||
|
||||
const testCase4 = "const path = require.resolve('module');";
|
||||
test(testCase4, () => {
|
||||
const src = testCase4;
|
||||
const code = transform(src, babelOptions)!.code;
|
||||
expect(code).toMatchInlineSnapshot(
|
||||
`"const path = electronRequire.resolve('module');"`,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user