{"id":13508278,"url":"https://github.com/atom/electron-link","last_synced_at":"2025-03-30T10:30:48.295Z","repository":{"id":41063548,"uuid":"73295811","full_name":"atom/electron-link","owner":"atom","description":"A module to bundle your electron app into a single file that can be used for V8 snapshots.","archived":true,"fork":false,"pushed_at":"2022-11-10T18:26:11.000Z","size":425,"stargazers_count":215,"open_issues_count":11,"forks_count":48,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-04-08T16:24:42.020Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-09T15:24:41.000Z","updated_at":"2024-02-29T06:16:00.000Z","dependencies_parsed_at":"2022-09-06T21:53:31.067Z","dependency_job_id":null,"html_url":"https://github.com/atom/electron-link","commit_stats":null,"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atom%2Felectron-link","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atom%2Felectron-link/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atom%2Felectron-link/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atom%2Felectron-link/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atom","download_url":"https://codeload.github.com/atom/electron-link/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246307603,"owners_count":20756473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:50.758Z","updated_at":"2025-03-30T10:30:47.875Z","avatar_url":"https://github.com/atom.png","language":"JavaScript","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) =\u003e 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","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatom%2Felectron-link","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatom%2Felectron-link","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatom%2Felectron-link/lists"}