-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
132 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.git | ||
.idea | ||
node_modules/ | ||
.temp | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export declare class PathfindingRuntime { | ||
readonly workerPath: string; | ||
constructor(workerPath: string); | ||
workerExists(): boolean; | ||
createWorker(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
// Import pre-builded inline worker as string | ||
import INLINE_WORKER from '../../.temp/worker.inline.js'; | ||
|
||
export class PathfindingRuntime { | ||
public readonly workerPath: string; | ||
|
||
constructor(workerPath: string) { | ||
this.workerPath = path.resolve(__dirname, workerPath); | ||
} | ||
|
||
public workerExists() { | ||
return fs.existsSync(this.workerPath); | ||
} | ||
|
||
public createWorker() { | ||
fs.writeFileSync(this.workerPath, INLINE_WORKER); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module '*.inline.js' { | ||
const content: string; | ||
export default content; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const path = require('path'); | ||
|
||
const InjectWorkerPlugin = require('./worker.plugin'); | ||
|
||
const root = path.resolve(__dirname, '..'); | ||
|
||
module.exports = { | ||
target: 'node', | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
}, | ||
entry: path.resolve(root, 'src/worker.ts'), | ||
output: { | ||
path: path.resolve(root, '.temp'), | ||
filename: 'worker.inline.js', | ||
libraryTarget: 'commonjs2', | ||
clean: true, | ||
}, | ||
plugins: [ | ||
new InjectWorkerPlugin(), | ||
], | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts$/, | ||
use: 'ts-loader', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
|
||
const ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers'); | ||
|
||
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], | ||
'`;', | ||
); | ||
} | ||
} | ||
} | ||
|
||
module.exports = InjectWorkerPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters