Split package "flipper-pkg" into two: lib and cli
Summary: "flipper-pkg" added ~2MB to Flipper disttributive size, because of heavy dependencies which are only required for CLI functionality. See size warning in diff D21068373 in this stack where I added pkg as dependency to flipper. Here I'm splitting it into library and CLI packages, so Flipper app will only reference the library. Reviewed By: passy Differential Revision: D21087336 fbshipit-source-id: d9d62f1e75a835d1c0fa78ff1addb0d9a761a9c7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4395b19140
commit
21b79af5f2
@@ -14,7 +14,7 @@ import * as inquirer from 'inquirer';
|
||||
import * as path from 'path';
|
||||
import * as yarn from '../utils/yarn';
|
||||
import cli from 'cli-ux';
|
||||
import runBuild from '../utils/runBuild';
|
||||
import {runBuild} from 'flipper-pkg-lib';
|
||||
|
||||
async function deriveOutputFileName(inputDirectory: string): Promise<string> {
|
||||
const packageJson = await readJSON(path.join(inputDirectory, 'package.json'));
|
||||
|
||||
@@ -9,5 +9,3 @@
|
||||
|
||||
export {run} from '@oclif/command';
|
||||
export const PKG = 'flipper-pkg';
|
||||
export {default as runBuild} from './utils/runBuild';
|
||||
export {default as getWatchFolders} from './utils/getWatchFolders';
|
||||
|
||||
10
desktop/pkg/src/types/metro.d.ts
vendored
10
desktop/pkg/src/types/metro.d.ts
vendored
@@ -1,10 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
declare module 'metro';
|
||||
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* 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 fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
|
||||
export default async (packageDir: string): Promise<string[]> => {
|
||||
if (!(await fs.pathExists(packageDir))) {
|
||||
return [];
|
||||
}
|
||||
const watchDirs: string[] = [packageDir];
|
||||
const pkg = await fs.readJson(path.join(packageDir, 'package.json'));
|
||||
while (true) {
|
||||
const nodeModulesDir = path.join(packageDir, 'node_modules');
|
||||
if (await fs.pathExists(nodeModulesDir)) {
|
||||
watchDirs.push(nodeModulesDir);
|
||||
const modules = await fs.readdir(nodeModulesDir);
|
||||
for (const moduleName of modules) {
|
||||
if (pkg.dependencies && pkg.dependencies[moduleName]) {
|
||||
const fullPath = path.join(nodeModulesDir, moduleName);
|
||||
const stat = await fs.lstat(fullPath);
|
||||
if (stat.isSymbolicLink()) {
|
||||
const target = await fs.readlink(fullPath);
|
||||
watchDirs.push(path.resolve(nodeModulesDir, target));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const nextDir = path.dirname(packageDir);
|
||||
if (!nextDir || nextDir === '/' || nextDir === packageDir) {
|
||||
break;
|
||||
}
|
||||
packageDir = nextDir;
|
||||
}
|
||||
return watchDirs;
|
||||
};
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* 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 Metro from 'metro';
|
||||
import getWatchFolders from './getWatchFolders';
|
||||
|
||||
function hash(string: string) {
|
||||
let hash = 0;
|
||||
if (string.length === 0) {
|
||||
return hash;
|
||||
}
|
||||
let chr;
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
chr = string.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + chr;
|
||||
hash |= 0;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
const fileToIdMap = new Map();
|
||||
const createModuleIdFactory = () => (filePath: string) => {
|
||||
if (filePath === '__prelude__') {
|
||||
return 0;
|
||||
}
|
||||
let id = fileToIdMap.get(filePath);
|
||||
if (typeof id !== 'number') {
|
||||
id = hash(filePath);
|
||||
fileToIdMap.set(filePath, id);
|
||||
}
|
||||
return id;
|
||||
};
|
||||
|
||||
export default async function runBuild(
|
||||
inputDirectory: string,
|
||||
entry: string,
|
||||
out: string,
|
||||
) {
|
||||
const baseConfig = await Metro.loadConfig();
|
||||
const config = Object.assign({}, baseConfig, {
|
||||
reporter: {update: () => {}},
|
||||
projectRoot: inputDirectory,
|
||||
watchFolders: [inputDirectory, ...(await getWatchFolders(inputDirectory))],
|
||||
serializer: {
|
||||
...baseConfig.serializer,
|
||||
getRunModuleStatement: (moduleID: string) =>
|
||||
`module.exports = global.__r(${moduleID}).default;`,
|
||||
createModuleIdFactory,
|
||||
},
|
||||
transformer: {
|
||||
...baseConfig.transformer,
|
||||
babelTransformerPath: require.resolve('flipper-babel-transformer'),
|
||||
},
|
||||
});
|
||||
await Metro.runBuild(config, {
|
||||
dev: false,
|
||||
minify: false,
|
||||
resetCache: false,
|
||||
sourceMap: true,
|
||||
entry,
|
||||
out,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user