Skip to content

Commit

Permalink
fix(config-cache): ensure cache folder for config file (js) is proper…
Browse files Browse the repository at this point in the history
…ly created before storing it
  • Loading branch information
GervinFung committed Sep 14, 2022
2 parents 193b7f4 + ff2abfa commit cb28faf
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 42 deletions.
8 changes: 4 additions & 4 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
/dist/
/docs/
/res/
/.yarn_home/
dist/
docs/
res/
.yarn_home/
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
"commander": "^4.1.1",
"comment-json": "^3.0.2",
"cosmiconfig": "^7.0.1",
"evt": "^2.4.1",
"evt": "^2.4.2",
"get-github-default-branch-name": "^0.0.4",
"gitignore-parser": "0.0.2",
"glob": "^7.1.6",
"minimal-polyfills": "^2.2.2",
"node-fetch": "^2.6.7",
"path-depth": "^1.0.0",
"scripting-tools": "^0.19.13",
"scripting-tools": "^0.19.14",
"tsafe": "^1.0.1",
"url-join": "^4.0.1",
"yaml": "^2.1.1"
Expand Down
19 changes: 15 additions & 4 deletions src/lib/parseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ export function configuration() {
}
}

function createDirIfNotExists(dir: string) {
if (!fs.existsSync(dir)) {
fs.mkdir(dir, () => undefined);
}
}

return {
"getFileTypeAndContent": (getConfigFileRawContent: (configFileBasename: string) => Promise<string | undefined>) => {
return supportedConfigFile.reduce(async (configFileType, file) => {
Expand Down Expand Up @@ -165,10 +171,15 @@ export function configuration() {
return parseAsDenoifyParams(configFileType.configFileBasename !== packageJson ? parsed : parsed.denoify);
}
case "js": {
const denoifyCacheDirPath = `${process.cwd()}/node_modules/.cache/denoify/cacheDirPath`;
if (!fs.existsSync(denoifyCacheDirPath)) {
fs.mkdir(denoifyCacheDirPath, () => undefined);
}
const cacheFolder = "node_modules/.cache";
createDirIfNotExists(cacheFolder);

const denoify = `${process.cwd()}/${cacheFolder}/denoify`;
createDirIfNotExists(denoify);

const denoifyCacheDirPath = `${denoify}/cacheDirPath`;
createDirIfNotExists(denoifyCacheDirPath);

const path = `${denoifyCacheDirPath}/config.js`;
fs.writeFileSync(path, configFileType.configFileRawContent);
// cosmiconfig internally uses import-fresh to parse JS config
Expand Down
22 changes: 11 additions & 11 deletions src/test/parseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { assert } from "tsafe";
[
{
type: "yaml",
file: ".denoifyrc.yaml",
config: `
configFileBasename: ".denoifyrc.yaml",
configFileRawContent: `
out:
${configDummy.out}
index:
Expand All @@ -28,8 +28,8 @@ index:
},
{
type: "json",
file: ".denoifyrc.json",
config: `
configFileBasename: ".denoifyrc.json",
configFileRawContent: `
{
"out": "${configDummy.out}",
"index": "${configDummy.index}"
Expand All @@ -38,8 +38,8 @@ index:
},
{
type: "js",
file: ".denoifyrc.js",
config: `
configFileBasename: ".denoifyrc.js",
configFileRawContent: `
module.exports = {
out: "${configDummy.out}",
index: "${configDummy.index}"
Expand All @@ -48,20 +48,20 @@ module.exports = {
},
{
type: "js",
file: ".denoifyrc.js",
config: `
configFileBasename: ".denoifyrc.js",
configFileRawContent: `
exports.name = {
out: "${configDummy.out}",
index: "${configDummy.index}"
}
`
}
] as const
).every(({ type, file, config }) => {
).every(({ type, configFileBasename, configFileRawContent }) => {
const yaml = configuration().parseAsDenoifyConfig({
type,
configFileBasename: file,
configFileRawContent: config
configFileBasename,
configFileRawContent
});
return yaml !== undefined && yaml.out === configDummy.out && yaml.index === configDummy.index;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,20 @@ import { runSequentially } from "../../../tools/runSequentially";

//TODO: Fix!
runSequentially({
"scriptsPaths": ["test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test8-bis", "test9", "test9-bis", "test10", "test11"]
"scriptsPaths": [
"test1",
"test2",
"test3",
"test4",
"test5",
"test6",
"test7",
"test8",
"test8-bis",
"test9",
"test9-bis",
"test10",
"test11",
"test12"
]
});
34 changes: 14 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,7 @@ core-util-is@^1.0.2:
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==

cosmiconfig@^7.0.0:
version "7.0.1"
resolved "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz"
integrity sha512-a1YWNUV2HwGimB7dU2s1wUMurNKjpx60HxBB6xUM8Re+2s1g1IIfJvFR0/iCF+XHdE0GMTKTuLR32UQff4TEyQ==
dependencies:
"@types/parse-json" "^4.0.0"
import-fresh "^3.2.1"
parse-json "^5.0.0"
path-type "^4.0.0"
yaml "^1.10.0"

cosmiconfig@^7.0.1:
cosmiconfig@^7.0.0, cosmiconfig@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-7.0.1.tgz#714d756522cace867867ccb4474c5d01bbae5d6d"
integrity sha512-a1YWNUV2HwGimB7dU2s1wUMurNKjpx60HxBB6xUM8Re+2s1g1IIfJvFR0/iCF+XHdE0GMTKTuLR32UQff4TEyQ==
Expand Down Expand Up @@ -456,10 +445,10 @@ esprima@^4.0.0, esprima@^4.0.1:
resolved "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz"
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==

evt@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/evt/-/evt-2.4.1.tgz#68beca2f7bd7eb755fdda5b263a80b934100e046"
integrity sha512-eo7sZcfDbiVWD5Aw6STkIEMmchYLdeGnJB6tVaM9AXZc7pViin3PmQhb6fgFIFHfl0re9zSEHtSjyu70Y7dRJg==
evt@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/evt/-/evt-2.4.2.tgz#8f29f53a71609f1f5ad09ba313ad8cc0b9c63077"
integrity sha512-wPGX4eGgxh5NRff+1VkRfdTRaJA5vbr9rC9CRUIgprVDGDFtI0/vF9I0Yp3HAEGuFbUO978QAsaH6lIgpRCFAg==
dependencies:
minimal-polyfills "^2.2.2"
run-exclusive "^2.2.16"
Expand Down Expand Up @@ -941,11 +930,16 @@ rxjs@^7.5.1:
dependencies:
tslib "^2.1.0"

scripting-tools@^0.19.12, scripting-tools@^0.19.13:
scripting-tools@^0.19.12:
version "0.19.13"
resolved "https://registry.npmjs.org/scripting-tools/-/scripting-tools-0.19.13.tgz"
integrity sha512-d09H8vzSVa8p4XUTJqHZDbjKDyl5TG3SyPfNPUUkfyOwjwykStmfK8AXyWq7VRWjcgzTpkTiJ9uMk1NytMQY7w==

scripting-tools@^0.19.14:
version "0.19.14"
resolved "https://registry.yarnpkg.com/scripting-tools/-/scripting-tools-0.19.14.tgz#d46cdea3dcf042b103b1712103b007e72c4901d5"
integrity sha512-KGRES70dEmcaCdpx3R88bLWmfA4mQ/EGikCQy0FGTZwx3y9F5yYkzEhwp02+ZTgpvF25JcNOhDBbOqL6z92kwg==

semver-compare@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz"
Expand Down Expand Up @@ -1090,9 +1084,9 @@ type-fest@^0.21.3:
integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==

typescript@^4.7.3:
version "4.7.4"
resolved "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==
version "4.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.3.tgz#d59344522c4bc464a65a730ac695007fdb66dd88"
integrity sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig==

universal-user-agent@^6.0.0:
version "6.0.0"
Expand Down

0 comments on commit cb28faf

Please sign in to comment.