Skip to content

Commit

Permalink
chore(*): update ci
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Jul 24, 2024
1 parent 51d8641 commit 602617b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 29 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ const weight = pathfinder.getWeight(
## Example

```ts
// index.ts

const pathfinding = new Pathfinding({
loopRate: 500,
});
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pathfinding-worker",
"description": "Fast node.js pathfinding on workers for grid-based games",
"version": "1.0.0",
"version": "1.0.1",
"keywords": [
"astar",
"dijkstra",
Expand All @@ -22,9 +22,10 @@
},
"main": "./dist/index.js",
"scripts": {
"build": "yarn build:worker && yarn build:entrypoint",
"build": "yarn build:worker && yarn build:entrypoint && yarn clear",
"build:worker": "webpack --config ./webpack/worker.config.js --mode production",
"build:entrypoint": "webpack --config ./webpack/entrypoint.config.js --mode production",
"clear": "rm -R ./.tmp",
"test": "jest",
"lint": "eslint \"./src/**/*.ts\" --fix"
},
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';

// Import pre-builded inline worker as string
import INLINE_WORKER from '../../.temp/worker.inline.js';
import INLINE_WORKER from '../../.tmp/worker.inline.js';

export class PathfindingRuntime {
public readonly workerPath: string;
Expand Down
3 changes: 3 additions & 0 deletions webpack/const.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
WEBPACK_INLINE_WORKER_TEMP_FILE_NAME: 'worker.inline.js',
};
5 changes: 3 additions & 2 deletions webpack/worker.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');

const { WEBPACK_INLINE_WORKER_TEMP_FILE_NAME } = require('./const');
const InjectWorkerPlugin = require('./worker.plugin');

const root = path.resolve(__dirname, '..');
Expand All @@ -11,8 +12,8 @@ module.exports = {
},
entry: path.resolve(root, 'src/worker.ts'),
output: {
path: path.resolve(root, '.temp'),
filename: 'worker.inline.js',
path: path.resolve(root, '.tmp'),
filename: WEBPACK_INLINE_WORKER_TEMP_FILE_NAME,
libraryTarget: 'commonjs2',
clean: true,
},
Expand Down
34 changes: 13 additions & 21 deletions webpack/worker.plugin.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */

const ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers');
const { WEBPACK_INLINE_WORKER_TEMP_FILE_NAME } = require('./const');

class InjectWorkerPlugin {
apply(compiler) {
const ConcatSource = compiler.webpack.sources.ConcatSource;
const tester = { test: this.test };

compiler.hooks.compilation.tap('InjectWorkerPlugin', (compilation) => {
compilation.hooks.afterOptimizeChunkAssets.tap('InjectWorkerPlugin', (chunks) => {
for (const chunk of chunks) {
for (const fileName of chunk.files) {
if (ModuleFilenameHelpers.matchObject(tester, fileName)) {
wrapFile(compilation, fileName);
}
}
}
});
});

function wrapFile(compilation, fileName) {
compilation.assets[fileName] = new ConcatSource(
'module.exports = `',
compilation.assets[fileName],
'`;',
);
}
compiler.hooks.compilation.tap(
'InjectWorkerPlugin',
({ hooks, assets }) => {
hooks.afterOptimizeChunkAssets.tap('InjectWorkerPlugin', () => {
assets[WEBPACK_INLINE_WORKER_TEMP_FILE_NAME] = new ConcatSource(
'module.exports = `',
assets[WEBPACK_INLINE_WORKER_TEMP_FILE_NAME],
'`;',
);
});
},
);
}
}

Expand Down

0 comments on commit 602617b

Please sign in to comment.