Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pittst3r committed Jul 6, 2020
1 parent 43148b3 commit 6bd0e8a
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 62 deletions.
6 changes: 6 additions & 0 deletions .changeset/from-parcel-to-rollup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@bigtest/bundler": minor
"@bigtest/server": minor
---

Refactor the manifest builder to use Rollup instead of Parcel.
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"extends": "@frontside",
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
"extends": "@frontside"
}
34 changes: 9 additions & 25 deletions packages/bundler/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
# @bigtest/parcel
# @bigtest/bundler

Control a parcel worker farm with visibility into key work events.
Control Rollup with visibility into key work events.

When parcel is running, it starts up a bunch of processes to do the
actual work of compilation and bundling in parallel. This is what we
want, but because of the way its implemented, it is possible that if
shutdown happens too quickly, or while it is in the middle of a
bundle, then it can leave a bunch of processes hanging around.

This solves the problem by wrapping an effection resource around a
parcel process and killing it off, and all children whenever it passes
out of scope.

Also, it isn't enough just to be running parcel, we have to know that
Also, it isn't enough just to be running Rollup, we have to know that
it is up and running, and when new builds are available. For this, the
parcel process implements the `receive()` method to get messages about
`Bundler` interface implements the `receive()` method to get messages about
when a new build is available.

## Synopsis

``` typescript
import { ParcelProcess } from '@bigtest/parcel';
import { Bundler } from '@bigtest/bundler';

function* start() {

// this operation does not complete until parcel is up and running
let parcel: ParcelProcess = yield ParcelProcess.create({
buildDir: './build',
srcPath: './tests/*.test.{js,ts}'
});
let bundler: Bundler = yield Bundler.create([{
entry: 'src/index.js',
outFile: 'dist/index.js'
}]);

while (true) {
let message = yield parcel.receive({ type: "update" });
Expand All @@ -37,12 +27,6 @@ function* start() {
}
```

## Development

``` shell
$ yarn start
```

## Testing

``` shell
Expand Down
5 changes: 2 additions & 3 deletions packages/bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@bigtest/bundler",
"version": "0.5.1",
"description": "Effection wrappers for working with a bundler",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"repository": "https://github.com/thefrontside/bigtest.git",
"author": "Frontside Engineering <[email protected]>",
"license": "MIT",
Expand All @@ -14,7 +14,6 @@
"scripts": {
"lint": "eslint 'src/**/*.ts' 'test/**/*.ts'",
"test": "mocha -r ts-node/register test/**/*.test.ts",
"start": "ts-node bin/start.ts",
"prepack": "tsc --outDir dist --declaration --sourcemap --module commonjs"
},
"dependencies": {
Expand Down
14 changes: 8 additions & 6 deletions packages/bundler/src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ export interface BundleOptions {
entry: string;
outFile: string;
globalName?: string;
}
};

export interface BundlerOptions {
mainFields: Array<"browser" | "main">;
};

function prepareRollupOptions(bundles: Array<BundleOptions>, { mainFields }: { mainFields: string[] } = { mainFields: ["browser", "main"] }): Array<RollupWatchOptions> {
function prepareRollupOptions(bundles: Array<BundleOptions>, { mainFields }: BundlerOptions = { mainFields: ["browser", "main"] }): Array<RollupWatchOptions> {
return bundles.map(bundle => {
return {
input: bundle.entry,
output: {
file: bundle.outFile,
name: bundle.globalName || undefined,
globals: {
"perf_hooks": "perf_hooks"
},
sourcemap: true,
format: 'umd',
},
external: ['perf_hooks'],
external: ['perf_hooks', '@babel/runtime'],
watch: {
exclude: ['node_modules/**']
},
Expand Down Expand Up @@ -61,6 +62,7 @@ function* waitForBuild(rollup: RollupWatcher) {
.filter(event => eventIs(event, 'END') || eventIs(event, 'ERROR'))
.map(event => {
if (eventIs(event, 'END')) return { type: 'update' };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (eventIs(event, 'ERROR')) return { type: 'error', error: (event as any).error };
throw new Error('Please file a bug report and include this stack trace');
}).first();
Expand Down
4 changes: 2 additions & 2 deletions packages/bundler/test/bundler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as rmrf from 'rimraf';
import { spawn } from './world';
import { Bundler } from '../src/index';

describe("Bundle Server", function() {
describe("Bundler", function() {
this.timeout(5000);
let bundler: Bundler;

Expand Down Expand Up @@ -95,7 +95,7 @@ describe("Bundle Server", function() {
});
});

describe('failure', () => {
describe('type error', () => {
beforeEach(async () => {
await fs.writeFile("./build/test/sources/input.ts", "const foo: number = 'bar';\nexport default foo;\n");

Expand Down
6 changes: 1 addition & 5 deletions packages/bundler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"extends": "@frontside/tsconfig",
"include": [
"build/**/*.ts",
"test/**/*.ts",
"src/**/*.ts"
]
"files": ["src/index.ts"]
}
2 changes: 2 additions & 0 deletions packages/cli/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ describe('@bigtest/cli', function() {

beforeEach(async () => {
await World.spawn(child.stdout?.waitFor("[orchestrator] running!"));

runChild = await World.spawn(run('test'));

await World.spawn(runChild.join());
});

Expand Down
10 changes: 6 additions & 4 deletions packages/server/src/manifest-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function* updateSourceMapURL(filePath: string, sourcemapName: string): Op
let readStream = fs.createReadStream(filePath, {start: size - 16});
let [currentURL]: [Buffer] = yield once(readStream, 'data');

if (currentURL.toString().trim().match(/manifest\.js\.map$/)) {
if (currentURL.toString().trim() === 'manifest.js.map') {
yield truncate(filePath, size - 16);
fs.appendFileSync(filePath, sourcemapName);
} else {
Expand Down Expand Up @@ -74,7 +74,6 @@ function* handleErrors(bundler: Bundler, delegate: Mailbox): Operation {
}

export function* createManifestBuilder(options: ManifestBuilderOptions): Operation {
let distPath: string;
let bundler: Bundler = yield Bundler.create(
[{
entry: options.srcPath,
Expand All @@ -84,11 +83,14 @@ export function* createManifestBuilder(options: ManifestBuilderOptions): Operati
);

yield handleErrors(bundler, options.delegate);
distPath = yield processManifest(options);

let distPath: string = yield processManifest(options);

console.debug("[manifest builder] manifest ready");

options.delegate.send({ status: "ready", path: distPath });

while(true) {
while (true) {
yield handleErrors(bundler, options.delegate);
let distPath = yield processManifest(options);

Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/fixtures/empty.t.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
module.exports = {
description: "An empty test with no steps and no children",
steps: [],
assertions: [],
children: []
};
}
2 changes: 1 addition & 1 deletion packages/server/test/fixtures/raw-tree-format.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ export default {
children: []
}
]
};
}
9 changes: 0 additions & 9 deletions packages/server/test/fixtures/syntax-error.t.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/server/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const actions = {
atom: this.atom,
project: {
port: 24102,
testFiles: ["test/fixtures/empty.t.js", "test/fixtures/raw-tree-format.t.js"],
testFiles: ["test/fixtures/*.t.js"],
cacheDir: "./tmp/test/orchestrator",
app: {
command: "yarn",
Expand Down

0 comments on commit 6bd0e8a

Please sign in to comment.