{"id":19560710,"url":"https://github.com/zoubin/deps-sort-integer-index-problem","last_synced_at":"2025-02-26T08:41:57.968Z","repository":{"id":145175633,"uuid":"38430241","full_name":"zoubin/deps-sort-integer-index-problem","owner":"zoubin","description":"`deps-sort` use increasing integer index, which may change every time the deps map changes","archived":false,"fork":false,"pushed_at":"2015-07-03T08:10:18.000Z","size":128,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-08T22:44:13.397Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoubin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-02T11:59:33.000Z","updated_at":"2015-07-02T12:58:31.000Z","dependencies_parsed_at":"2023-03-31T03:43:24.970Z","dependency_job_id":null,"html_url":"https://github.com/zoubin/deps-sort-integer-index-problem","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fdeps-sort-integer-index-problem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fdeps-sort-integer-index-problem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fdeps-sort-integer-index-problem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fdeps-sort-integer-index-problem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoubin","download_url":"https://codeload.github.com/zoubin/deps-sort-integer-index-problem/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240822615,"owners_count":19863302,"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-11-11T05:08:32.180Z","updated_at":"2025-02-26T08:41:57.910Z","avatar_url":"https://github.com/zoubin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deps-sort-integer-index-problem\n`deps-sort` use increasing integer index, which may change every time the deps map changes\n\nThis happens when browserify works together with [factor-bundle](https://www.npmjs.com/package/factor-bundle).\n\nThis repo will give an example.\n\nThere is a [plugin](https://www.npmjs.com/package/index-hashify) to fix it, before browserify or deps-sort gives a solution.\n\n## Example\n\n* `a.js` depends upon `base.js`\n* we use `factor-bundle` to build two bundles, and only `base.js` will go to `common.js` (built from `b.bundle()` stream)\n* after bundle, we can see that `base.js` gets id `2`, and `a.js` `1`\n* if we `require('b.js')` in `a.js` (like `a.modified.js`), though `b.js` will be kept out of `common.js`, `base.js` now gets id `3`. That means we have changed the contents of `common.js` and the browser cache will be invalidated.\n\nHere is the script:\n\n```javascript\nvar browserify = require('browserify');\nvar factor = require('factor-bundle');\nvar path = require('path');\nvar merge = require('merge-stream');\nvar fs = require('fs');\nvar sink = require('sink-transform');\n\nvar file = path.join(__dirname, process.argv[2]);\nvar b = browserify(file);\n\nvar a = wrap(file);\n\nb.plugin(factor, {\n    entries: file,\n    outputs: a,\n    threshold: function (row, groups) {\n        return path.basename(row.file) === 'base.js';\n    }\n});\n\nmerge([a, wrap(b.bundle())]).pipe(process.stdout);\n\nfunction wrap(s) {\n    var tr = sink.str(function (body, done) {\n        this.push([\n            '',\n            '='.repeat(80),\n            typeof s === 'string' \u0026\u0026 s || 'common',\n            '-'.repeat(80),\n            body,\n            ''\n        ].join('\\n'))\n        done();\n    });\n\n    if (typeof s === 'string') {\n        return tr;\n    }\n    return s.pipe(tr);\n}\n```\n\n`a.js`:\n\n```javascript\nvar c = require('./base.js');\n\nmodule.exports = 'a';\n```\n\n`a.modified.js`:\n\n```javascript\nvar c = require('./base.js');\nvar b = require('./b.js');\n\nmodule.exports = 'a';\n```\n\n`b.js`:\n\n```javascript\nmodule.exports = 'b';\n```\n\n`base.js`:\n\n```javascript\nmodule.exports = 'common';\n```\n\n\n### built from `a.js`\n\n```\n⌘ node index.js a.js\n\n================================================================================\n/Users/zoubin/usr/src/zoubin/deps-sort-integer-index-problem/a.js\n--------------------------------------------------------------------------------\nrequire=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"\u0026\u0026require;if(!u\u0026\u0026a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"\u0026\u0026require;for(var o=0;o\u003cr.length;o++)s(r[o]);return s})({1:[function(require,module,exports){\nvar c = require('./base.js');\n\nmodule.exports = 'a';\n\n},{\"./base.js\":2}]},{},[1]);\n\n\n================================================================================\ncommon\n--------------------------------------------------------------------------------\nrequire=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"\u0026\u0026require;if(!u\u0026\u0026a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"\u0026\u0026require;for(var o=0;o\u003cr.length;o++)s(r[o]);return s})({2:[function(require,module,exports){\nmodule.exports = 'common';\n\n},{}]},{},[]);\n```\n\n### built from `a.modified.js`\nThe contents of `common` module has changed due to the changed id (from `2` to `3`)!\n\n```\n⌘ node index.js a.modified.js\n\n================================================================================\n/Users/zoubin/usr/src/zoubin/deps-sort-integer-index-problem/a.modified.js\n--------------------------------------------------------------------------------\nrequire=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"\u0026\u0026require;if(!u\u0026\u0026a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"\u0026\u0026require;for(var o=0;o\u003cr.length;o++)s(r[o]);return s})({1:[function(require,module,exports){\nvar c = require('./base.js');\nvar b = require('./b.js');\n\nmodule.exports = 'a';\n\n},{\"./b.js\":2,\"./base.js\":3}],2:[function(require,module,exports){\nmodule.exports = 'b';\n\n},{}]},{},[1]);\n\n\n================================================================================\ncommon\n--------------------------------------------------------------------------------\nrequire=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"\u0026\u0026require;if(!u\u0026\u0026a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"\u0026\u0026require;for(var o=0;o\u003cr.length;o++)s(r[o]);return s})({3:[function(require,module,exports){\nmodule.exports = 'common';\n\n},{}]},{},[]);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Fdeps-sort-integer-index-problem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoubin%2Fdeps-sort-integer-index-problem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Fdeps-sort-integer-index-problem/lists"}