Skip to content

Commit

Permalink
chore: move ram bundle plugin to core (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
Noemi Rozpara authored Apr 27, 2020
1 parent d7319a2 commit 5e8fca4
Show file tree
Hide file tree
Showing 29 changed files with 49 additions and 107 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"test": "jest",
"clean": "rimraf ./packages/*/build ./packages/*/tsconfig.tsbuildinfo",
"watch": "yarn clean && concurrently \"yarn:watch:source\" \"yarn:watch:ts\"",
"build:source": "lerna --ignore @haul-bundler/basic-bundle-webpack-plugin exec --parallel \"babel src --out-dir build --extensions .js,.ts,.tsx --source-maps --config-file=../../babel.config.js\"",
"watch:source": "lerna --ignore @haul-bundler/basic-bundle-webpack-plugin exec --parallel \"babel src --out-dir build --extensions .js,.ts,.tsx --source-maps --config-file=../../babel.config.js --watch\"",
"build:source": "lerna --ignore \"@haul-bundler/{basic-bundle-webpack-plugin,ram-bundle-webpack-plugin}\" exec --parallel \"babel src --out-dir build --extensions .js,.ts,.tsx --source-maps --config-file=../../babel.config.js\"",
"watch:source": "lerna --ignore \"@haul-bundler/{basic-bundle-webpack-plugin,ram-bundle-webpack-plugin}\" exec --parallel \"babel src --out-dir build --extensions .js,.ts,.tsx --source-maps --config-file=../../babel.config.js --watch\"",
"build:ts": "node ./scripts/build_ts.js",
"watch:ts": "node ./scripts/build_ts.js --watch",
"prepare": "yarn clean && yarn build:source && yarn build:ts",
Expand Down
7 changes: 4 additions & 3 deletions packages/haul-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "build/index.js",
"files": [
"build/",
"assets/"
"assets/",
"runtime/"
],
"engines": {
"node": ">=10.x"
Expand All @@ -15,7 +16,8 @@
"license": "MIT",
"bugs": "https://github.com/callstack/haul/issues",
"peerDependencies": {
"react-native": ">=0.59.0"
"react-native": ">=0.59.0",
"metro": ">= 0.51.1 < 1"
},
"dependencies": {
"@babel/core": "7.4.0",
Expand All @@ -29,7 +31,6 @@
"@hapi/joi": "^15.1.1",
"@haul-bundler/basic-bundle-webpack-plugin": "^0.18.0",
"@haul-bundler/core-legacy": "^0.17.0",
"@haul-bundler/ram-bundle-webpack-plugin": "^0.17.0",
"ansi-fragments": "^0.2.1",
"dedent": "^0.7.0",
"enhanced-resolve": "^4.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ Object {
},
},
},
WebpackRamBundlePlugin {
RamBundleWebpackPlugin {
"bundleId": "app",
"bundleName": "app",
"indexRamBundle": true,
"maxWorkers": 7,
"minify": false,
"minifyOptions": undefined,
"modules": Array [],
"name": "WebpackRamBundlePlugin",
"name": "RamBundleWebpackPlugin",
"preloadBundles": Array [
"base_dll",
],
Expand Down Expand Up @@ -212,15 +212,15 @@ Object {
},
},
},
WebpackRamBundlePlugin {
RamBundleWebpackPlugin {
"bundleId": "base_dll",
"bundleName": "base_dll",
"indexRamBundle": true,
"maxWorkers": 7,
"minify": false,
"minifyOptions": undefined,
"modules": Array [],
"name": "WebpackRamBundlePlugin",
"name": "RamBundleWebpackPlugin",
"preloadBundles": Array [],
"singleBundleMode": false,
"sourceMap": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('makeConfig', () => {
};
const config = makeConfig(projectConfig)(runtime, env);
expect(
hasPlugin(config.webpackConfigs.index, 'WebpackRamBundlePlugin')
hasPlugin(config.webpackConfigs.index, 'RamBundleWebpackPlugin')
).toBeTruthy();
});

Expand All @@ -157,7 +157,7 @@ describe('makeConfig', () => {
};
const config = makeConfig(projectConfig)(runtime, env);
expect(
hasPlugin(config.webpackConfigs.index, 'WebpackRamBundlePlugin')
hasPlugin(config.webpackConfigs.index, 'RamBundleWebpackPlugin')
).toBeTruthy();
});

Expand Down Expand Up @@ -216,7 +216,7 @@ describe('makeConfig', () => {
hasPlugin(config.webpackConfigs.index, 'BasicBundleWebpackPlugin')
).toBeTruthy();
expect(
hasPlugin(config.webpackConfigs.index, 'WebpackRamBundlePlugin')
hasPlugin(config.webpackConfigs.index, 'RamBundleWebpackPlugin')
).toBeFalsy();
});

Expand Down Expand Up @@ -320,10 +320,10 @@ describe('makeConfig', () => {
hasPlugin(config.webpackConfigs.index, 'BasicBundleWebpackPlugin')
).toBeTruthy();
expect(
hasPlugin(config.webpackConfigs.base_dll, 'WebpackRamBundlePlugin')
hasPlugin(config.webpackConfigs.base_dll, 'RamBundleWebpackPlugin')
).toBeTruthy();
expect(
hasPlugin(config.webpackConfigs.app, 'WebpackRamBundlePlugin')
hasPlugin(config.webpackConfigs.app, 'RamBundleWebpackPlugin')
).toBeTruthy();
expect(replacePathsInObject(config)).toMatchSnapshot();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/haul-core/src/preset/makeConfigFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import webpack from 'webpack';
import path from 'path';
import { cpus } from 'os';
import isCi from 'is-ci';
import RamBundlePlugin from '@haul-bundler/ram-bundle-webpack-plugin';
import {
Runtime,
EnvOptions,
Expand All @@ -26,6 +25,7 @@ import applySingleBundleTweaks from './utils/applySingleBundleTweaks';
import applyMultiBundleTweaks from './utils/applyMultiBundleTweaks';
import LooseModeWebpackPlugin from '../webpack/plugins/LooseModeWebpackPlugin';
import InitCoreDllPlugin from '../webpack/plugins/InitCoreDllPlugin';
import RamBundlePlugin from '../webpack/plugins/RamBundleWebpackPlugin';
import BasicBundleWebpackPlugin from '../webpack/plugins/BasicBundleWebpackPlugin';

type GetDefaultConfig = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import webpack from 'webpack';
import path from 'path';
import { RawSource } from 'webpack-sources';
import MAGIC_NUMBER from 'metro/src/shared/output/RamBundle/magic-number';
import { Module } from './WebpackRamBundlePlugin';
import { Module } from './RamBundleWebpackPlugin';

export default class FileRamBundle {
constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MAGIC_NUMBER from 'metro/src/shared/output/RamBundle/magic-number';
import webpack from 'webpack';
import { RawSource } from 'webpack-sources';
import { Module } from './WebpackRamBundlePlugin';
import { Module } from './RamBundleWebpackPlugin';

/***
* Reference: https://github.com/facebook/metro/blob/master/packages/metro/src/shared/output/RamBundle/as-indexed-file.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ModuleMappings = {
chunks: { [key: string]: Array<number | string> };
};

type WebpackRamBundlePluginOptions = {
type RamBundleWebpackPluginOptions = {
singleBundleMode?: boolean;
sourceMap?: boolean;
indexRamBundle?: boolean;
Expand All @@ -63,8 +63,8 @@ const variableToString = (value?: string | number) => {
const hasValue = (value: any): boolean =>
typeof value === 'undefined' ? false : true;

export default class WebpackRamBundlePlugin {
name = 'WebpackRamBundlePlugin';
export default class RamBundleWebpackPlugin {
name = 'RamBundleWebpackPlugin';

modules: Module[] = [];
sourceMap: boolean = false;
Expand All @@ -74,7 +74,7 @@ export default class WebpackRamBundlePlugin {
bundleName: string = 'index';
singleBundleMode: boolean = true;
minify: boolean = false;
minifyOptions: WebpackRamBundlePluginOptions['minifyOptions'] = undefined;
minifyOptions: RamBundleWebpackPluginOptions['minifyOptions'] = undefined;
maxWorkers: number;

constructor({
Expand All @@ -87,7 +87,7 @@ export default class WebpackRamBundlePlugin {
maxWorkers,
bundleId,
bundleName,
}: WebpackRamBundlePluginOptions) {
}: RamBundleWebpackPluginOptions) {
this.sourceMap = Boolean(sourceMap);
this.indexRamBundle = Boolean(indexRamBundle);
this.preloadBundles = preloadBundles || [];
Expand All @@ -103,7 +103,7 @@ export default class WebpackRamBundlePlugin {

apply(compiler: webpack.Compiler) {
compiler.hooks.emit.tapPromise(
'WebpackRamBundlePlugin',
'RamBundleWebpackPlugin',
async _compilation => {
// Cast compilation from @types/webpack to custom Compilation type
// which contains additional properties.
Expand Down Expand Up @@ -139,18 +139,23 @@ export default class WebpackRamBundlePlugin {

if (mainId === undefined) {
throw new Error(
"WebpackRamBundlePlugin: couldn't find main chunk's entry module id"
"RamBundleWebpackPlugin: couldn't find main chunk's entry module id"
);
}
if (!mainChunk) {
throw new Error("WebpackRamBundlePlugin: couldn't find main chunk");
throw new Error("RamBundleWebpackPlugin: couldn't find main chunk");
}
// Render modules to it's 'final' form with injected webpack variables
// and wrapped with ModuleTemplate.
const minifyWorker = new Worker(require.resolve('../build/worker'), {
numWorkers: this.maxWorkers,
enableWorkerThreads: true,
});
const minifyWorker = new Worker(
require.resolve(
'../../../../build/webpack/plugins/RamBundleWebpackPlugin/worker'
),
{
numWorkers: this.maxWorkers,
enableWorkerThreads: true,
}
);

this.modules = await Promise.all(
compilation.modules.map(async webpackModule => {
Expand Down Expand Up @@ -213,12 +218,15 @@ export default class WebpackRamBundlePlugin {

const indent = (line: string) => `/*****/ ${line}`;
let bootstrap = fs.readFileSync(
path.join(__dirname, '../runtime/bootstrap.js'),
path.join(
__dirname,
'../../../../runtime/webpack/plugin/ram-bundle-webpack-plugin/bootstrap.js'
),
'utf8'
);
if (typeof this.bundleName !== 'string' || !this.bundleName.length) {
throw new Error(
'WebpackRamBundlePlugin: bundle name cannot be empty string'
'RamBundleWebpackPlugin: bundle name cannot be empty string'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'fs';
import assert from 'assert';
import { SourceMapConsumer } from 'source-map';
import RamBundleParser from 'metro/src/lib/RamBundleParser';
import RamBundlePlugin from '../WebpackRamBundlePlugin';
import RamBundlePlugin from '../RamBundleWebpackPlugin';

function wait(ms: number) {
return new Promise(resolve => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './RamBundleWebpackPlugin';
9 changes: 2 additions & 7 deletions packages/haul-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@
"rootDir": "src",
"outDir": "build",
"jsx": "react"
},
"references": [
{
"path": "../haul-ram-bundle-webpack-plugin"
}
]
}
}
}
File renamed without changes.
43 changes: 1 addition & 42 deletions packages/haul-ram-bundle-webpack-plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
# @haul-bundler/ram-bundle-webpack-plugin

[![Version][version]][package]

[![PRs Welcome][prs-welcome-badge]][prs-welcome]
[![MIT License][license-badge]][license]
[![Chat][chat-badge]][chat]
[![Code of Conduct][coc-badge]][coc]

RAM bundle plugin for Haul and Webpack. This module is intended for internal use. __Supports RN 0.59+__.

__When using `@haul-bundler/cli ram-bundle` command, this plugin will be added and configured automatically__, based on passed options.

You can read more about Haul here: https://github.com/callstack/haul.

## API

```ts
import WebpackRamBundlePlugin from '@haul-bundler/ram-bundle-webpack-plugin';

new WebpackRamBundlePlugin({
sourceMap: true, // whether to generate source maps
indexRamBundle: true, // whether to build Indexed RAM bundle or File RAM bundle
preloadBundles: [], // name of bundles to preload when running in multi-bundle mode
singleBundleMode: true, // whether to run in single-bundle mode or multi-bundle
minify: true, // enables minifcation
minifyOptions: { /* ... */ }, // Terser minify options (excluding `sourceMap`)
maxWorkers: 1, // number of workers to use, should not be higher than number of available threads - 1
});
```

<!-- badges (common) -->

[license-badge]: https://img.shields.io/npm/l/@haul-bundler/ram-bundle-webpack-plugin.svg?style=flat-square
[license]: https://opensource.org/licenses/MIT
[prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
[prs-welcome]: http://makeapullrequest.com
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
[coc]: https://github.com/callstack/haul/blob/master/CODE_OF_CONDUCT.md
[chat-badge]: https://img.shields.io/badge/chat-discord-brightgreen.svg?style=flat-square&colorB=7289DA&logo=discord
[chat]: https://discord.gg/zwR2Cdh

[version]: https://img.shields.io/npm/v/@haul-bundler/ram-bundle-webpack-plugin.svg?style=flat-square
[package]: https://www.npmjs.com/package/@haul-bundler/ram-bundle-webpack-plugin
`RamBundleWebpackPlugin` was moved into `@haul-bundler/core` package. This module exists only for backwards compatibility and should not be used.
1 change: 1 addition & 0 deletions packages/haul-ram-bundle-webpack-plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@haul-bundler/core/dist/webpack/plugins/RamBundleWebpackPlugin');
5 changes: 0 additions & 5 deletions packages/haul-ram-bundle-webpack-plugin/jest.config.js

This file was deleted.

16 changes: 3 additions & 13 deletions packages/haul-ram-bundle-webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@
"version": "0.17.0",
"name": "@haul-bundler/ram-bundle-webpack-plugin",
"description": "RAM bundle plugin for Haul and Webpack",
"main": "build/index.js",
"files": [
"build/",
"runtime/"
],
"main": "index.js",
"author": "Pawel Trysla <pawel.trysla@callstack.com>",
"repository": "github:callstack/haul",
"license": "MIT",
"bugs": "https://github.com/callstack/haul/issues",
"peerDependencies": {
"metro": ">= 0.51.1 < 1",
"terser": "4.x",
"webpack": "4.x",
"webpack-sources": "1.x"
"@haul-bundler/core": ">=0.19.0"
},
"gitHead": "c41becc82dfeafb07b642ebed8f082775647ec3f",
"dependencies": {
"jest-worker": "^25.1.0"
}
"gitHead": "c41becc82dfeafb07b642ebed8f082775647ec3f"
}
1 change: 0 additions & 1 deletion packages/haul-ram-bundle-webpack-plugin/src/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/haul-ram-bundle-webpack-plugin/tsconfig.json

This file was deleted.

0 comments on commit 5e8fca4

Please sign in to comment.