{"_id":"@alex313031/electron-link","name":"@alex313031/electron-link","dist-tags":{"latest":"0.6.3"},"versions":{"0.6.3":{"name":"@alex313031/electron-link","version":"0.6.3","description":"Generates scripts to pass to V8's `mksnapshot` tool.","homepage":"https://github.com/Alex313031/electron-link-ng#readme","main":"lib/index.js","scripts":{"test":"mocha test/**/*.test.js --ui=tdd","tdd":"electron-mocha test/**/*.test.js --ui=tdd --renderer --interactive --no-sandbox","clean":"rm -r -f node_modules/"},"author":{"name":"Alex313031","email":"https://github.com/Alex313031"},"license":"MIT","devDependencies":{"dedent":"0.7.0","electron":"12.2.3","electron-mocha":"^11.0.2","mocha":"^9.2.2","rimraf":"3.0.2","temp":"0.9.4"},"dependencies":{"acorn":"^8.1.1","ast-util-plus":"^0.7.1","encoding-down":"^6.3.0","indent-string":"^4.0.0","leveldown":"^5.6.0","levelup":"^4.4.0","recast":"^0.20.5","resolve":"^1.21.0","source-map":"^0.7.4"},"directories":{"lib":"lib","test":"test"},"repository":{"type":"git","url":"git+https://github.com/Alex313031/electron-link-ng.git"},"bugs":{"url":"https://github.com/Alex313031/electron-link-ng/issues"},"gitHead":"188674b804c380c30543fb9eb2716d44e75fb363","_id":"@alex313031/electron-link@0.6.3","_nodeVersion":"14.21.3","_npmVersion":"6.14.18","dist":{"integrity":"sha512-ESjxWwMWgEdeaZ7lDnQ/1BIYG0QmUa4i5QKRUd6emENxMWXze0jWs1kc3WiZne0EfjvC2w4aZirQU+mn78rKNw==","shasum":"34244426b07e34961cb90d04b8d19891fbdf3d74","tarball":"https://registry.npmjs.org/@alex313031/electron-link/-/electron-link-0.6.3.tgz","fileCount":10,"unpackedSize":49671,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCmTbEWoPxpDi7sR4VxZ/w8qyzJPz7fjQwJ3bet/hKCTAIhAPjk0m1lLbMjkcUPG1AN9YgIt7kQf3ccs94DOIrG6Chz"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHlA1ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqFKg/7BsE1T3NJa88qmWdfnd3Vvpzlr2rYnO7Xalxry+JIS/B3ewYq\r\nbV09vxm9FU779DiOVRKAaK/SDiUJq5WvBWDxhc4opWe3wBWamZsyO+Tccsky\r\neXrxvyoTfcVviMXFh4imgTTJq2A4MpP2FsR2rR+MIk7SsmcgHrdLt4A7BmYv\r\n+iKxbT1ZLSSxznGpHF+31OtKNQUFmK5FdjsTa3spLAoHfgPnlE2mCqLDDXF3\r\nIH2sZr9HyQpUMJ9etudiQtISv04BWe+82zF4t/uupApLss8u8duZfY6vZM/y\r\nFrMVcxZ7W+JoocY58Q4+NY4CAlpQHZvVKTT6xWmFlOZWTCeLFr63xpPaXhkO\r\nOmKpHG93B1rBcCPMGk9nuapRqhBD6Uz7IajGEB8G5vsTM31GJhgmxzFKJm3n\r\n0LE9owQpH/Y9Ajbcsf++PM6NroO3LsF552HvAJ7ixlPnHy3IZlJl806IOuGW\r\nOS/k7LUkdPGGOm39gPOamG582yEZ+svEr/bOO7XuAnlFJ7YNUHzqZl5mg5QR\r\nF8DrlAFH7KvmS/wwz6QhPH3ljDIYqT9aQ8lOTtFETHeuPdaVyz4XOB3BAqR0\r\nRqr6qdM6qtynYhzf3VKufWxWx93mJJKf1PmEyFxvrOfbZl5wGS90WMmq04dw\r\n+5cd/BPo+Y2YHbBhPl3fnkp36hf+ohsINOk=\r\n=MWy+\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alex313031","email":"Alex313031@gmail.com"},"maintainers":[{"name":"alex313031","email":"Alex313031@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/electron-link_0.6.3_1679708213538_0.7613589238535263"},"_hasShrinkwrap":false}},"time":{"created":"2023-03-25T01:36:53.488Z","0.6.3":"2023-03-25T01:36:53.719Z","modified":"2023-03-25T01:36:53.887Z"},"maintainers":[{"name":"alex313031","email":"Alex313031@gmail.com"}],"description":"Generates scripts to pass to V8's `mksnapshot` tool.","homepage":"https://github.com/Alex313031/electron-link-ng#readme","repository":{"type":"git","url":"git+https://github.com/Alex313031/electron-link-ng.git"},"author":{"name":"Alex313031","email":"https://github.com/Alex313031"},"bugs":{"url":"https://github.com/Alex313031/electron-link-ng/issues"},"license":"MIT","readme":"##### Atom and all repositories under Atom will be archived on December 15, 2022. Learn more in our [official announcement](https://github.blog/2022-06-08-sunsetting-atom/)\n # electron-link\n\nelectron-link is a node module that takes a JavaScript file (typically the entry point of an application) and a list of modules that need to be required lazily (see [Atom's build scripts](https://github.com/atom/atom/blob/d9ebd7e125d5f07def1a057a0a8278d4d9d7d23a/script/lib/generate-startup-snapshot.js#L19-L65) for an example). Then, starting from that file, it traverses the entire require graph and replaces all the forbidden `require` calls in each file with a function that will be called at runtime. The output is a single script containing the code for all the modules reachable from the entry point. This file can be then supplied to `mksnapshot` to generate a snapshot blob.\n\nIt can also determine whether a module can be snapshotted or not. For instance, the following code can be snapshotted:\n\n```js\nconst path = require('path')\n\nmodule.exports = function () {\n  return path.join('a', 'b', 'c')\n}\n```\n\nAnd generates the following code:\n\n```js\nlet path;\nfunction get_path () {\n  return path || path = require('path');\n}\n\nmodule.exports = function () {\n  return get_path().join('a', 'b', 'c')\n}\n```\n\nYou can notice that the above code is valid because the forbidden module (i.e. `path`) is used inside a function that doesn't get called when requiring the script. On the other hand, when trying to process the following code, electron-link will throw an error because it is trying to access a forbidden module right when it gets required:\n\n```js\nconst path = require('path')\n\nmodule.exports = path.join('a', 'b', 'c')\n```\n\nBeing a tool based on static analysis, however, electron-link is unable to detect all the cases where a piece of code can't be included in a snapshot. Therefore, we recommend running the generated JavaScript file in an empty V8 context (similar to the one provided by `mksnapshot`) to catch any invalid code that might have slipped through.\n\n## Installation\n\n```bash\nnpm install --save electron-link\n```\n\n## Usage\n\n```js\nconst electronLink = require('electron-link')\n\nconst snapshotScript = await electronLink({\n  baseDirPath: '/base/dir/path',\n  mainPath: '/base/dir/path/main.js',\n  cachePath: '/cache/path',\n  shouldExcludeModule: (modulePath) => excludedModules.has(modulePath)\n})\n\nconst snapshotScriptPath = '/path/to/snapshot/script.js'\nfs.writeFileSync(snapshotScriptPath, snapshotScript)\n\n// Verify if we will be able to use this in `mksnapshot`\nvm.runInNewContext(snapshotScript, undefined, {filename: snapshotScriptPath, displayErrors: true})\n```\n\n","readmeFilename":"README.md"}