Skip to content

Commit

Permalink
Fix worker paths and add missing filename
Browse files Browse the repository at this point in the history
  • Loading branch information
MonicaOlejniczak committed Oct 18, 2024
1 parent 0820fa1 commit 3408179
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"check": "flow check",
"lint": "eslint . && prettier \"./packages/*/*/{src,bin,test}/**/*.{js,json,md}\" --list-different && cargo fmt --all -- --check",
"prepublishOnly": "yarn adjust-versions && yarn build && yarn build-ts",
"test:unit": "cross-env NODE_ENV=test mocha --timeout 5000 && cargo test",
"test:unit": "cross-env NODE_ENV=test mocha --conditions=development --timeout 5000 && cargo test",
"test:integration": "yarn workspace @atlaspack/integration-tests test",
"test:integration-ci": "yarn workspace @atlaspack/integration-tests test-ci",
"test": "yarn test:unit && yarn test:integration",
Expand Down
7 changes: 7 additions & 0 deletions packages/core/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
"graphviz": "^0.0.9",
"tempy": "^0.2.1"
},
"exports": {
".": "./lib/index.js",
"./worker": {
"development": "./src/worker.js",
"default": "./lib/worker.js"
}
},
"browser": {
"./src/serializerCore.js": "./src/serializerCore.browser.js"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/Atlaspack.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ export function createWorkerFarm(
...options,
// $FlowFixMe
workerPath: process.browser
? '@atlaspack/core/src/worker.js'
? '@atlaspack/core/worker'
: require.resolve('./worker'),
});
}
2 changes: 1 addition & 1 deletion packages/core/core/test/RequestTracker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {toProjectPath} from '../src/projectPath';
import {DEFAULT_FEATURE_FLAGS, setFeatureFlags} from '../../feature-flags/src';

const options = DEFAULT_OPTIONS;
const farm = new WorkerFarm({workerPath: require.resolve('../src/worker.js')});
const farm = new WorkerFarm({workerPath: require.resolve('../src/worker')});

describe('RequestTracker', () => {
it('should not run requests that have not been invalidated', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/test/requests/ConfigRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const mockCast = (f: any): any => f;
describe('ConfigRequest tests', () => {
const projectRoot = 'project_root';
const farm = new WorkerFarm({
workerPath: require.resolve('../../src/worker.js'),
workerPath: require.resolve('../../src/worker'),
maxConcurrentWorkers: 1,
});
let fs = new MemoryFS(farm);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/fs/test/OverlayFS.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('OverlayFS', () => {

beforeEach(() => {
workerFarm = new WorkerFarm({
workerPath: require.resolve('@atlaspack/core/src/worker.js'),
workerPath: require.resolve('@atlaspack/core/worker'),
});
underlayFS = new MemoryFS(workerFarm);
fs = new OverlayFS(workerFarm, underlayFS);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/atlassian-labs/atlaspack.git"
},
"scripts": {
"test": "cross-env NODE_ENV=test ATLASPACK_BUILD_ENV=test mocha --experimental-vm-modules",
"test": "cross-env NODE_ENV=test ATLASPACK_BUILD_ENV=test mocha --conditions=development --experimental-vm-modules",
"test-ci": "yarn test --config .mocharc.ci.json"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('NodePackageManager', function () {

beforeEach(() => {
workerFarm = new WorkerFarm({
workerPath: require.resolve('@atlaspack/core/src/worker.js'),
workerPath: require.resolve('@atlaspack/core/worker'),
});
fs = new OverlayFS(new MemoryFS(workerFarm), new NodeFS());
packageInstaller = new MockPackageInstaller();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test-utils/test/fsFixture.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ describe('fsFixture', () => {

beforeEach(() => {
workerFarm = new WorkerFarm({
workerPath: require.resolve('@atlaspack/core/src/worker.js'),
workerPath: require.resolve('@atlaspack/core/worker'),
});
fs = new MemoryFS(workerFarm);
});
Expand Down Expand Up @@ -608,7 +608,7 @@ describe('toFixture', () => {

beforeEach(() => {
workerFarm = new WorkerFarm({
workerPath: require.resolve('@atlaspack/core/src/worker.js'),
workerPath: require.resolve('@atlaspack/core/worker'),
});
fs = new MemoryFS(workerFarm);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/workers/src/WorkerFarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class WorkerFarm extends EventEmitter {

// $FlowFixMe
if (process.browser) {
if (this.options.workerPath === '@atlaspack/core/src/worker.js') {
if (this.options.workerPath === '@atlaspack/core/worker') {
this.localWorker = coreWorker;
} else {
throw new Error(
Expand Down Expand Up @@ -357,7 +357,7 @@ export default class WorkerFarm extends EventEmitter {
} else if (location) {
// $FlowFixMe
if (process.browser) {
if (location === '@atlaspack/workers/src/bus.js') {
if (location === '@atlaspack/workers/bus') {
mod = (bus: any);
} else {
throw new Error('No dynamic require possible: ' + location);
Expand Down
4 changes: 1 addition & 3 deletions packages/core/workers/src/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ class Bus extends EventEmitter {
child.workerApi.callMaster(
{
// $FlowFixMe
location: process.browser
? '@atlaspack/workers/src/bus.js'
: __filename,
location: process.browser ? '@atlaspack/workers/bus' : __filename,
method: 'emit',
args: [event, ...args],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/workers/src/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Child {
async childInit(module: string, childId: number): Promise<void> {
// $FlowFixMe
if (process.browser) {
if (module === '@atlaspack/core/src/worker.js') {
if (module === '@atlaspack/core/worker') {
this.module = coreWorker;
} else {
throw new Error('No dynamic require possible: ' + module);
Expand Down
5 changes: 3 additions & 2 deletions packages/core/workers/src/core-worker.browser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
// eslint-disable-next-line monorepo/no-internal-import
module.exports = require('@atlaspack/core/src/worker.js');

// $FlowFixMe
module.exports = require('@atlaspack/core/worker');
3 changes: 1 addition & 2 deletions packages/core/workers/src/process/ProcessWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import type {
WorkerMessage,
} from '../types';
import childProcess, {type ChildProcess} from 'child_process';
import path from 'path';
import {serialize, deserialize} from '@atlaspack/core';

const WORKER_PATH = path.join(__dirname, 'ProcessChild.js');
const WORKER_PATH = require.resolve('./ProcessChild');

export default class ProcessWorker implements WorkerImpl {
execArgv: Object;
Expand Down
3 changes: 1 addition & 2 deletions packages/core/workers/src/threads/ThreadsWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import type {
WorkerMessage,
} from '../types';
import {Worker} from 'worker_threads';
import path from 'path';
import {
prepareForSerialization,
restoreDeserializedObject,
} from '@atlaspack/core';

const WORKER_PATH = path.join(__dirname, 'ThreadsChild.js');
const WORKER_PATH = require.resolve('./ThreadsChild');

export default class ThreadsWorker implements WorkerImpl {
execArgv: Object;
Expand Down
10 changes: 7 additions & 3 deletions packages/dev/eslint-plugin/test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ const pkgPath = pkgInfo.path;
const pkgName = pkgInfo.pkg.name;

describe('utils', () => {
let opts = {
babelOptions: {filename: 'test.js'},
};

describe('isRequire', () => {
it('identifies requires', () => {
assert.equal(
isStaticRequire(
getFirstExpression(parse("require('@atlaspack/core')")),
getFirstExpression(parse("require('@atlaspack/core')"), opts),
),
true,
);
});

it("doesn't handle dynamic requires", () => {
assert.equal(
isStaticRequire(getFirstExpression(parse('require(dynamic)'))),
isStaticRequire(getFirstExpression(parse('require(dynamic)'), opts)),
false,
);
});
Expand All @@ -38,7 +42,7 @@ describe('utils', () => {
it('identifies built-in require.resolve', () => {
assert.equal(
isStaticResolve(
getFirstExpression(parse("require.resolve('@atlaspack/core')")),
getFirstExpression(parse("require.resolve('@atlaspack/core')"), opts),
),
true,
);
Expand Down

0 comments on commit 3408179

Please sign in to comment.