-
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.
Chore(repo): Introduce Yarn plugin for overriding state
* this should solve the problem with non-existing node modules state file * @see: heroku/heroku-buildpack-nodejs#907
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const ALLOWED_SCRIPTS=["build"]; | ||
|
||
const NODE_MODULES="node_modules"; | ||
const STATE_FILE=".yarn-state.yml"; | ||
|
||
module.exports = { | ||
name: `plugin-override-state`, | ||
factory: require => ({ | ||
hooks: { | ||
async setupScriptEnvironment(project, scriptEnv) { | ||
if (scriptEnv != null && ALLOWED_SCRIPTS.find(script => script == scriptEnv.npm_lifecycle_event) != null) { | ||
if (project.configuration.get(`nodeLinker`) === `node-modules`) { | ||
const stateFile = [project.cwd, NODE_MODULES, STATE_FILE].join("/"); | ||
const fs = require("fs"); | ||
|
||
if (!fs.existsSync(stateFile)) { | ||
console.log("Detected command allowed in stateless environment and state file is missing."); | ||
console.log("Generating empty state file..."); | ||
|
||
fs.mkdirSync(require('path').dirname(stateFile), { recursive: true }); | ||
fs.appendFileSync(stateFile, "# Autogenerated\n", {"flag":"w+"}); | ||
fs.appendFileSync(stateFile, "__metadata:\n"); | ||
fs.appendFileSync(stateFile, " version: 1\n"); | ||
fs.appendFileSync(stateFile, " nmMode: classic\n"); | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
}) | ||
}; |
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