This repository has been archived by the owner on Nov 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Conditionally run npm install
in tmp directory
#8
Closed
Closed
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0ba3715
chore(repo): add .DS_Store to gitignore
kylebjordahl 51587a3
chore(repo): add include path to tsconfig
kylebjordahl 7a589e9
feat(caxa): run npm install if needed
kylebjordahl 1159cd7
fix(caxa): refactor logic to fallback to npm i
kylebjordahl 1eb76ae
chore(caxa): clean up console log
kylebjordahl 6e05eca
chore(caxa): remove extra `.catch()`
kylebjordahl 0804366
feat(caxa): add filter option to caxa api
kylebjordahl 2c79261
Merge branch 'master' of github.com:kylebjordahl/caxa
kylebjordahl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/node_modules/ | ||
/lib/ | ||
.DS_Store |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -30,6 +30,27 @@ export default async function caxa({ | |||||
); | ||||||
const appDirectory = path.join(os.tmpdir(), "caxa", identifier); | ||||||
await fs.copy(directory, appDirectory); | ||||||
|
||||||
// if we did not copy a node modules folder, but there is a package or package-lock file, run npm install | ||||||
if (!(await fs.pathExists(path.join(appDirectory, "node_modules")))) { | ||||||
const packageLockPath = path.join(appDirectory, "package-lock.json"); | ||||||
const packageJsonPath = path.join(appDirectory, "package.json"); | ||||||
// prefer using package-lock, if available | ||||||
try { | ||||||
if (await fs.pathExists(packageLockPath)) { | ||||||
await execa("npm", ["ci"], { cwd: appDirectory }).catch(); | ||||||
} else if (await fs.pathExists(packageJsonPath)) { | ||||||
throw null; | ||||||
} | ||||||
} catch (err) { | ||||||
try { | ||||||
await execa("npm", ["i"], { cwd: appDirectory }); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here as above (#8 (comment)) |
||||||
} catch (e) { | ||||||
// pass, nothing we can do here | ||||||
console.log(e); | ||||||
} | ||||||
} | ||||||
} | ||||||
await execa("npm", ["prune", "--production"], { cwd: appDirectory }); | ||||||
await execa("npm", ["dedupe"], { cwd: appDirectory }); | ||||||
await fs.ensureDir(path.join(appDirectory, "node_modules/.bin")); | ||||||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"include": ["src/**/*.ts"], | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "lib", | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why did you add a
.catch()
here but not on thenpm i
below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on the catch (pun intended) - it was from a previous approach I had which didn't have the try blocks.
I'm actually intentionally NOT limiting it to production, because one of the example repos runs
tsc
as part of itsprepare
script, which fails without the dev dependency of typescript.But we still run
npm prune
to clear out the production dependencies before bundling, so this feels acceptable to me. Perhaps we add an optional flag to force production-only installation if you know you don't need the option of dev dependencies for this step?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kylebjordahl Ah, I see! Makes sense. I thought of this as an optimization, but you're right, there are situations in which installing it all is necessary. I'd say to just leave it the way you did.