1

I'm reading through the source code for the game "Screeps" (trying to reverse-engineer how it executes user-provided scripts in a safe way, to use in games of my own), and I've come across a line I don't understand.

Line 10 in this file reads:

    driver = require('~runtime-driver');

What does the tilde mean here? This doesn't seem to refer to a local file or a separate package, so where is it locating the driver?

The engine runs on node, and here are the dependencies from package.json:

  "dependencies": {
    "@screeps/pathfinding": "^0.4.16",
    "bulk-require": "^0.2.1",
    "cross-env": "^5.2.0",
    "lodash": "3.10.1",
    "q": "^1.0.1"
  },
  "devDependencies": {
    "babel-plugin-transform-es2015-destructuring": "^6.23.0",
    "babel-plugin-transform-strict-mode": "^6.24.1",
    "babel-preset-es2015": "^6.24.1",
    "cross-env": "^5.2.0",
    "gulp": "^3.9.1",
    "gulp-babel": "^6.1.2",
    "gulp-plumber": "^1.1.0",
    "gulp-sourcemaps": "^2.6.0",
    "gulp-traceur": "^0.17.2",
    "gulp-watch": "^4.3.11",
    "jasmine": "^3.3.0"
  },

(Reading this, could it be a babel thing?)

Thanks!

Tim Leach
  • 87
  • 10
  • 1
    I think it's similar to import: https://stackoverflow.com/questions/43113870/what-is-the-tilde-doing-in-this-javascript-import – Barmar Sep 12 '22 at 16:25
  • I think that the tilde means it's looking for the file in the [home directory of the interpreter \(modules\)](https://www.ibm.com/docs/en/aix/7.2?topic=shell-tilde-substitution) – Sir Archibald Humphrey Sep 12 '22 at 16:26

1 Answers1

1

It's a Webpack thing.

For this project, what ~runtime-driver resolves to is defined here:

resolve: {
  alias: {
    '~runtime-driver': require.resolve('./lib/runtime/runtime-driver')
  }
}
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • Amazing, thank you! Follow-up, how does it know to use the alias given in a different repo? Does webpack grab all the webpack config from all the _other_ things you import before doing its bundle? – Tim Leach Sep 13 '22 at 10:24
  • 1
    @TimLeach I got the impression that even though there are different repo's, everything should be installed inside the same directory (or will end up in the same directory after installation or setting up). I think Webpack itself is git-agnostic. – robertklep Sep 13 '22 at 10:38