Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 'yarn start' on Windows - LavaPack is not defined (#13318) #16550

Merged
merged 4 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion development/build/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const terser = require('terser');

const bifyModuleGroups = require('bify-module-groups');

const phishingWarningManifest = require('@metamask/phishing-warning/package.json');
const { streamFlatMap } = require('../stream-flat-map');
const { BuildType } = require('../lib/build-type');
const { generateIconNames } = require('../generate-icon-names');
const phishingWarningManifest = require('../../node_modules/@metamask/phishing-warning/package.json');
const { BUILD_TARGETS, ENVIRONMENT } = require('./constants');
const { getConfig, getProductionConfig } = require('./config');
const {
Expand Down
25 changes: 15 additions & 10 deletions development/build/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { BuildType } = require('../lib/build-type');

const { TASKS } = require('./constants');
const { createTask, composeSeries } = require('./task');
const { getPathInsideNodeModules } = require('./utils');

const EMPTY_JS_FILE = './development/empty.js';

Expand Down Expand Up @@ -115,7 +116,7 @@ function getCopyTargets(shouldIncludeLockdown) {
dest: `images`,
},
{
src: `./node_modules/@metamask/contract-metadata/images/`,
src: getPathInsideNodeModules('@metamask/contract-metadata', 'images/'),
dest: `images/contract`,
},
{
Expand All @@ -127,11 +128,14 @@ function getCopyTargets(shouldIncludeLockdown) {
dest: `vendor`,
},
{
src: `./node_modules/@fortawesome/fontawesome-free/webfonts/`,
src: getPathInsideNodeModules(
'@fortawesome/fontawesome-free',
'webfonts/',
),
dest: `fonts/fontawesome`,
},
{
src: `./node_modules/react-responsive-carousel/lib/styles`,
src: getPathInsideNodeModules('react-responsive-carousel', 'lib/styles/'),
dest: 'react-gallery/',
},
{
Expand All @@ -144,12 +148,12 @@ function getCopyTargets(shouldIncludeLockdown) {
dest: `loading.html`,
},
{
src: `./node_modules/globalthis/dist/browser.js`,
src: getPathInsideNodeModules('globalthis', 'dist/browser.js'),
dest: `globalthis.js`,
},
{
src: shouldIncludeLockdown
? `./node_modules/ses/dist/lockdown.umd.min.js`
? getPathInsideNodeModules('ses', 'dist/lockdown.umd.min.js')
: EMPTY_JS_FILE,
dest: `lockdown-install.js`,
},
Expand All @@ -170,13 +174,11 @@ function getCopyTargets(shouldIncludeLockdown) {
dest: `lockdown-more.js`,
},
{
// eslint-disable-next-line node/no-extraneous-require
src: require.resolve('@lavamoat/lavapack/src/runtime-cjs.js'),
src: getPathInsideNodeModules('@lavamoat/lavapack', 'src/runtime-cjs.js'),
dest: `runtime-cjs.js`,
},
{
// eslint-disable-next-line node/no-extraneous-require
src: require.resolve('@lavamoat/lavapack/src/runtime.js'),
src: getPathInsideNodeModules('@lavamoat/lavapack', 'src/runtime.js'),
dest: `runtime-lavamoat.js`,
},
];
Expand All @@ -190,7 +192,10 @@ function getCopyTargets(shouldIncludeLockdown) {

for (const tag of languageTags) {
allCopyTargets.push({
src: `./node_modules/@formatjs/intl-relativetimeformat/dist/locale-data/${tag}.json`,
src: getPathInsideNodeModules(
'@formatjs/intl-relativetimeformat',
`dist/locale-data/${tag}.json`,
),
dest: `intl/${tag}/relative-time-format-data.json`,
});
}
Expand Down
24 changes: 24 additions & 0 deletions development/build/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
const semver = require('semver');
const { BuildType } = require('../lib/build-type');
const { BUILD_TARGETS, ENVIRONMENT } = require('./constants');
Expand Down Expand Up @@ -117,10 +118,33 @@ function logError(error) {
console.error(error.stack || error);
}

/**
* Get the path of a file or folder inside the node_modules folder
*
* require.resolve was causing errors on Windows, once the paths were fed into fast-glob
* (The backslashes had to be converted to forward-slashes)
* This helper function was written to fix the Windows problem, and also end reliance on writing paths that start with './node_modules/'
*
* @see {@link https://github.com/MetaMask/metamask-extension/pull/16550}
* @param {string} packageName - The name of the package, such as '@lavamoat/lavapack'
* @param {string} pathToFiles - The path of the file or folder inside the package, optionally starting with /
*/
function getPathInsideNodeModules(packageName, pathToFiles) {
let targetPath = path.dirname(require.resolve(`${packageName}/package.json`));

targetPath = path.join(targetPath, pathToFiles);

// Force POSIX separators
targetPath = targetPath.split(path.sep).join(path.posix.sep);

return targetPath;
}

module.exports = {
getBrowserVersionMap,
getEnvironment,
isDevBuild,
isTestBuild,
logError,
getPathInsideNodeModules,
};
2 changes: 1 addition & 1 deletion test/e2e/seeder/smart-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
collectiblesBytecode,
failingContractAbi,
failingContractBytecode,
} = require('../../../node_modules/@metamask/test-dapp/dist/constants.json');
} = require('@metamask/test-dapp/dist/constants.json');

const hstFactory = {
initialAmount: 100,
Expand Down