Skip to content

Commit

Permalink
Scaffolding memory leaks (#1538)
Browse files Browse the repository at this point in the history
* Refactored scaffold task to resolve memory leaks. However, there are still some present

* Committing work thus far

* Fixed problem with memory leaks for the scaffold task

* Re-enable a skipped test for CORS

Co-authored-by: Houston <32914364+hu3man@users.noreply.github.com>
  • Loading branch information
Michael Weichert and hu3man authored Nov 23, 2022
1 parent b2bcf62 commit 83767fd
Show file tree
Hide file tree
Showing 9 changed files with 2,360 additions and 309 deletions.
118 changes: 61 additions & 57 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {
bimap,
chain,
chainRej,
coalesce,
debugMode,
forkCatch,
FutureInstance as Future,
go,
map,
mapRej,
parallel,
Expand Down Expand Up @@ -62,7 +64,7 @@ const {
eager,
isTaqError,
taqResolve,
// logInput,
logInput,
// debug
} = utils.inject({
stdout: Deno.stdout,
Expand Down Expand Up @@ -236,12 +238,6 @@ const initCLI = (env: EnvVars, args: DenoArgs, i18n: i18n.t) => {
default: './taqueria-taco-shop',
});
},
(args: Record<string, unknown>) =>
pipe(
SanitizedArgs.ofScaffoldTaskArgs(args),
chain(scaffoldProject(i18n)),
forkCatch(displayError(cliConfig))(displayError(cliConfig))(console.log),
),
);
};

Expand Down Expand Up @@ -430,59 +426,61 @@ const initProject = (
map(_ => i18n.__('bootstrapMsg')),
);

const runScaffoldPostInit = (scaffoldDir: SanitizedAbsPath.t): Future<TaqError.t, SanitizedAbsPath.t> => {
const scaffoldConfigAbspath = SanitizedAbsPath.create(`${scaffoldDir}/scaffold.json`);
return pipe(
readJsonFile<ScaffoldConfig.t>(scaffoldConfigAbspath),
map(logInput('Scaffold Config')),
coalesce(_ => ({}) as ScaffoldConfig.t)(identity),
chain(scaffoldConfig =>
typeof scaffoldConfig === 'object' && scaffoldConfig.postInit
? pipe(
exec(`${scaffoldConfig.postInit!} 2>&1`, {}, true, scaffoldDir),
map(JSON.stringify),
chain(appendTextFile(joinPaths(scaffoldDir, 'scaffold.log'))),
chain(_ =>
pipe(
rm(scaffoldConfigAbspath),
coalesce(_ => scaffoldConfigAbspath)(_ => scaffoldConfigAbspath),
)
),
)
: taqResolve(scaffoldConfigAbspath)
),
);
};

const scaffoldProject = (i18n: i18n.t) =>
({ scaffoldUrl, scaffoldProjectDir, maxConcurrency }: SanitizedArgs.ScaffoldTaskArgs) =>
attemptP<TaqError.t, string>(async () => {
const abspath = await eager(SanitizedAbsPath.make(scaffoldProjectDir));
const destDir = await eager(doesPathNotExistOrIsEmptyDir(abspath));

log(`\n Scaffolding 🛠 \n into: ${destDir}\n from: ${scaffoldUrl} \n`);
await eager(gitClone(scaffoldUrl)(destDir));

log('\n Initializing Project...');

const gitDir = await eager(SanitizedAbsPath.make(`${destDir}/.git`));
await eager(rm(gitDir));
log(' ✓ Remove Git directory');

const installOutput = await eager(exec(`npm install 2>&1`, {}, true, destDir));
await eager(appendTextFile(joinPaths(destDir, 'scaffold.log'))(installOutput.toString()));
log(' ✓ Install plugins');

const initOutput = await eager(exec(`taq init 2>&1`, {}, true, destDir));
await eager(appendTextFile(joinPaths(destDir, 'scaffold.log'))(initOutput.toString()));

// Remove the scaffold.json file, if not exists
// If it doesn't exist, don't throw...
const scaffoldConfigAbspath = await eager(SanitizedAbsPath.make(`${destDir}/scaffold.json`));
try {
const scaffoldConfig = await eager(readJsonFile<ScaffoldConfig.t>(scaffoldConfigAbspath));
if (
typeof scaffoldConfig === 'object' && Object.hasOwn(scaffoldConfig, 'postInit') && scaffoldConfig.postInit
) {
const setupOutput = await eager(exec(`${scaffoldConfig.postInit!} 2>&1`, {}, true, destDir));
await eager(appendTextFile(joinPaths(destDir, 'scaffold.log'))(setupOutput.toString()));
}
} catch (err) {
if (!isTaqError(err) || err.kind !== 'E_INVALID_PATH_DOES_NOT_EXIST') {
throw err;
}
}
try {
await eager(rm(scaffoldConfigAbspath));
} catch (err) {
if (!isTaqError(err) || err.kind !== 'E_INVALID_PATH_DOES_NOT_EXIST') {
throw err;
}
}
log(' ✓ Run scaffold post-init script');
go(
function*() {
const abspath = yield SanitizedAbsPath.make(scaffoldProjectDir);
const destDir = yield doesPathNotExistOrIsEmptyDir(abspath);

log(" ✓ Project Taq'ified \n");
log(`\n Scaffolding 🛠 \n into: ${destDir}\n from: ${scaffoldUrl} \n`);
yield gitClone(scaffoldUrl)(destDir);

return ('🌮 Project created successfully 🌮');
log('\n Initializing Project...');

// return i18n.__("scaffoldDoneMsg")
});
const gitDir = yield SanitizedAbsPath.make(`${destDir}/.git`);
yield rm(gitDir);
log(' ✓ Remove Git directory');

const installOutput = yield exec(`npm install 2>&1`, {}, true, destDir);
yield appendTextFile(joinPaths(destDir, 'scaffold.log'))(installOutput.toString());
log(' ✓ Install plugins');

const initOutput = yield exec(`taq init 2>&1`, {}, true, destDir);
yield appendTextFile(joinPaths(destDir, 'scaffold.log'))(initOutput.toString());

yield runScaffoldPostInit(abspath);
log(' ✓ Run scaffold post-init script');

log(" ✓ Project Taq'ified \n");

return ('🌮 Project created successfully 🌮');
},
);

const getCanonicalTask = (pluginName: string, taskName: string, state: EphemeralState.t) =>
state.plugins.reduce(
Expand Down Expand Up @@ -1014,16 +1012,22 @@ export const run = (env: EnvVars, inputArgs: DenoArgs, i18n: i18n.t) => {
} else if (initArgs.build) {
log(initArgs.setBuild);
return taqResolve(initArgs);
} else if (initArgs._.includes('scaffold')) {
return pipe(
SanitizedArgs.ofScaffoldTaskArgs(initArgs),
chain(scaffoldProject(i18n)),
map(_ => initArgs),
);
}

return initArgs._.includes('init')
|| initArgs._.includes('testFromVsCode')
|| initArgs._.includes('scaffold')
|| initArgs._.includes('opt-in')
|| initArgs._.includes('opt-out')
? taqResolve(initArgs)
: postInitCLI(cliConfig, env, processedInputArgs, initArgs, i18n);
}),
chain((initArgs: SanitizedArgs.t) =>
chain(initArgs =>
sendEvent(
initArgs._.join(),
getVersion(inputArgs),
Expand Down
62 changes: 31 additions & 31 deletions deno-lock.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/deno/ts-pattern.js": "139329135ba186e1f4d171fb5f8c4412f634b516cd86d9eebd144c818c8b4690",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/guards.d.ts": "23d3ac26c35d4ea250f4f6fa07b659bd29c927a9b2820538566b6cb4430b28c3",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/index.d.ts": "9be090eb63ebe134cd5016ce8619bec07146219443604c34232a548303f262d8",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/symbols.d.ts": "98319b603cf3f3a8b5b2c41de042cde79d84b690f26c0b4685e4e672df8ca404",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/types/BuildMany.d.ts": "3674e53f36e6e41ba02338325facde0d9a955de5d7fd688498f587782db88093",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/types/DeepExclude.d.ts": "5c60171c7dd994fe164c8bbf3fc8ea24c38e59b28d591f5aabeff38ec88c6412",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/types/DistributeUnions.d.ts": "ea6d9a52a1dcafa3e3b00638585ab474f1ee12742047df8650f2dafda2e7b23e",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/types/ExtractPreciseValue.d.ts": "9e1e400b20494dfc0b76dbb958fbeb4d1ab1d466ede399d68cf0f48f0fb8c739",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/types/FindSelected.d.ts": "566c9855f7664544a79da7c90fa5f7d9d56410984e7fed1692860df71c121ebb",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/types/InvertPattern.d.ts": "02923619121da147c587d07cf4fe44cff411ff30f1f73c73e75d7649ff680407",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/types/IsMatching.d.ts": "cec8189326776ce185aaec51fca5e7614febfd698371250fe5f05ce839ace71e",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/types/Match.d.ts": "63e07e40910e6e8d4c4f08027aca1e7397aa31673a9dbfed50c9442b0800995b",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/types/Pattern.d.ts": "f30e3728c2943012603e55ab32cf3553ecf62a4cb90702169bddd8028aee7a35",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/types/helpers.d.ts": "93e97f7a2715e8391e59ffd02e23773fdd9184c041719cb4e52821501b3995d0",
"https://cdn.esm.sh/v76/ts-pattern@3.3.5/lib/wildcards.d.ts": "c1bfcc56d4e49285e3254b407a36325dd2f099dba94fe7dee68d992d1fc35429",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/deno/ts-pattern.js": "8c2bb24215369ea60f00888d9bd6d31e2f5541e75b1ef9f423ab20a21e80d99b",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/guards.d.ts": "23d3ac26c35d4ea250f4f6fa07b659bd29c927a9b2820538566b6cb4430b28c3",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/index.d.ts": "9be090eb63ebe134cd5016ce8619bec07146219443604c34232a548303f262d8",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/symbols.d.ts": "98319b603cf3f3a8b5b2c41de042cde79d84b690f26c0b4685e4e672df8ca404",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/types/BuildMany.d.ts": "3674e53f36e6e41ba02338325facde0d9a955de5d7fd688498f587782db88093",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/types/DeepExclude.d.ts": "5c60171c7dd994fe164c8bbf3fc8ea24c38e59b28d591f5aabeff38ec88c6412",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/types/DistributeUnions.d.ts": "ea6d9a52a1dcafa3e3b00638585ab474f1ee12742047df8650f2dafda2e7b23e",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/types/ExtractPreciseValue.d.ts": "9e1e400b20494dfc0b76dbb958fbeb4d1ab1d466ede399d68cf0f48f0fb8c739",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/types/FindSelected.d.ts": "566c9855f7664544a79da7c90fa5f7d9d56410984e7fed1692860df71c121ebb",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/types/InvertPattern.d.ts": "02923619121da147c587d07cf4fe44cff411ff30f1f73c73e75d7649ff680407",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/types/IsMatching.d.ts": "cec8189326776ce185aaec51fca5e7614febfd698371250fe5f05ce839ace71e",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/types/Match.d.ts": "63e07e40910e6e8d4c4f08027aca1e7397aa31673a9dbfed50c9442b0800995b",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/types/Pattern.d.ts": "f30e3728c2943012603e55ab32cf3553ecf62a4cb90702169bddd8028aee7a35",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/types/helpers.d.ts": "93e97f7a2715e8391e59ffd02e23773fdd9184c041719cb4e52821501b3995d0",
"https://cdn.esm.sh/v74/ts-pattern@3.3.5/lib/wildcards.d.ts": "c1bfcc56d4e49285e3254b407a36325dd2f099dba94fe7dee68d992d1fc35429",
"https://cdn.jsdelivr.net/gh/fluture-js/Fluture@14.0.0/dist/module.js": "c11481f8a52a4ceabe6fb971abd0783b79ed7eb8a3eb2e2c4f3a3c8a1afa3303",
"https://cdn.jsdelivr.net/gh/fluture-js/Fluture@14.0.0/index.d.ts": "7f0d5888ab9f39515ee8f83df99377f63428ae65aa5e4daf3034035c773ea211",
"https://cdn.skypack.dev/-/batching-toposort@v1.2.0-dHlz5M75ZjMJ8fm1NtwH/dist=es2019,mode=imports/optimized/batching-toposort.js": "9508ff2861e25b728b4015df6a75aae993195da7279ec92a59294ba825751d6e",
Expand Down Expand Up @@ -48,28 +48,28 @@
"https://deno.land/std@0.120.0/path/posix.ts": "34349174b9cd121625a2810837a82dd8b986bbaaad5ade690d1de75bbb4555b2",
"https://deno.land/std@0.120.0/path/separator.ts": "8fdcf289b1b76fd726a508f57d3370ca029ae6976fcde5044007f062e643ff1c",
"https://deno.land/std@0.120.0/path/win32.ts": "11549e8c6df8307a8efcfa47ad7b2a75da743eac7d4c89c9723a944661c8bd2e",
"https://deno.land/std@0.123.0/_util/assert.ts": "2f868145a042a11d5ad0a3c748dcf580add8a0dbc0e876eaa0026303a5488f58",
"https://deno.land/std@0.123.0/_util/os.ts": "dfb186cc4e968c770ab6cc3288bd65f4871be03b93beecae57d657232ecffcac",
"https://deno.land/std@0.123.0/fmt/colors.ts": "8368ddf2d48dfe413ffd04cdbb7ae6a1009cf0dccc9c7ff1d76259d9c61a0621",
"https://deno.land/std@0.123.0/fmt/printf.ts": "419510e0a3f7c8d680fbf6472d5a11e372854f1c2b32fca5fdb513575c485068",
"https://deno.land/std@0.123.0/path/_constants.ts": "1247fee4a79b70c89f23499691ef169b41b6ccf01887a0abd131009c5581b853",
"https://deno.land/std@0.123.0/path/_interface.ts": "1fa73b02aaa24867e481a48492b44f2598cd9dfa513c7b34001437007d3642e4",
"https://deno.land/std@0.123.0/path/_util.ts": "2e06a3b9e79beaf62687196bd4b60a4c391d862cfa007a20fc3a39f778ba073b",
"https://deno.land/std@0.123.0/path/common.ts": "f41a38a0719a1e85aa11c6ba3bea5e37c15dd009d705bd8873f94c833568cbc4",
"https://deno.land/std@0.123.0/path/glob.ts": "7bf2349e818e332a830f3d8874c3f45dd7580b6c742ed50dbf6282d84ab18405",
"https://deno.land/std@0.123.0/path/mod.ts": "4465dc494f271b02569edbb4a18d727063b5dbd6ed84283ff906260970a15d12",
"https://deno.land/std@0.123.0/path/posix.ts": "34349174b9cd121625a2810837a82dd8b986bbaaad5ade690d1de75bbb4555b2",
"https://deno.land/std@0.123.0/path/separator.ts": "8fdcf289b1b76fd726a508f57d3370ca029ae6976fcde5044007f062e643ff1c",
"https://deno.land/std@0.123.0/path/win32.ts": "11549e8c6df8307a8efcfa47ad7b2a75da743eac7d4c89c9723a944661c8bd2e",
"https://deno.land/std@0.123.0/testing/_diff.ts": "e6a10d2aca8d6c27a9c5b8a2dbbf64353874730af539707b5b39d4128140642d",
"https://deno.land/std@0.123.0/testing/asserts.ts": "437505f8490a4d261836d822d3418bdd2b152007bdc9b01bdc339bf4b88983a2",
"https://deno.land/std@0.128.0/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74",
"https://deno.land/std@0.128.0/bytes/bytes_list.ts": "67eb118e0b7891d2f389dad4add35856f4ad5faab46318ff99653456c23b025d",
"https://deno.land/std@0.128.0/bytes/equals.ts": "fc16dff2090cced02497f16483de123dfa91e591029f985029193dfaa9d894c9",
"https://deno.land/std@0.128.0/bytes/mod.ts": "d3b455c0dbd4804644159d1e25946ade5ee385d2359894de49e2c6101b18b7a9",
"https://deno.land/std@0.128.0/io/buffer.ts": "bd0c4bf53db4b4be916ca5963e454bddfd3fcd45039041ea161dbf826817822b",
"https://deno.land/std@0.128.0/io/types.d.ts": "01f60ae7ec02675b5dbed150d258fc184a78dfe5c209ef53ba4422b46b58822c",
"https://deno.land/std@0.128.0/streams/conversion.ts": "712585bfa0172a97fb68dd46e784ae8ad59d11b88079d6a4ab098ff42e697d21",
"https://deno.land/std@0.133.0/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74",
"https://deno.land/std@0.133.0/_util/os.ts": "49b92edea1e82ba295ec946de8ffd956ed123e2948d9bd1d3e901b04e4307617",
"https://deno.land/std@0.133.0/fmt/colors.ts": "30455035d6d728394781c10755351742dd731e3db6771b1843f9b9e490104d37",
"https://deno.land/std@0.133.0/fmt/printf.ts": "e2c0f72146aed1efecf0c39ab928b26ae493a2278f670a871a0fbdcf36ff3379",
"https://deno.land/std@0.133.0/path/_constants.ts": "df1db3ffa6dd6d1252cc9617e5d72165cd2483df90e93833e13580687b6083c3",
"https://deno.land/std@0.133.0/path/_interface.ts": "ee3b431a336b80cf445441109d089b70d87d5e248f4f90ff906820889ecf8d09",
"https://deno.land/std@0.133.0/path/_util.ts": "c1e9686d0164e29f7d880b2158971d805b6e0efc3110d0b3e24e4b8af2190d2b",
"https://deno.land/std@0.133.0/path/common.ts": "bee563630abd2d97f99d83c96c2fa0cca7cee103e8cb4e7699ec4d5db7bd2633",
"https://deno.land/std@0.133.0/path/glob.ts": "cb5255638de1048973c3e69e420c77dc04f75755524cb3b2e160fe9277d939ee",
"https://deno.land/std@0.133.0/path/mod.ts": "4275129bb766f0e475ecc5246aa35689eeade419d72a48355203f31802640be7",
"https://deno.land/std@0.133.0/path/posix.ts": "663e4a6fe30a145f56aa41a22d95114c4c5582d8b57d2d7c9ed27ad2c47636bb",
"https://deno.land/std@0.133.0/path/separator.ts": "fe1816cb765a8068afb3e8f13ad272351c85cbc739af56dacfc7d93d710fe0f9",
"https://deno.land/std@0.133.0/path/win32.ts": "e7bdf63e8d9982b4d8a01ef5689425c93310ece950e517476e22af10f41a136e",
"https://deno.land/std@0.133.0/testing/_diff.ts": "9d849cd6877694152e01775b2d93f9d6b7aef7e24bfe3bfafc4d7a1ac8e9f392",
"https://deno.land/std@0.133.0/testing/asserts.ts": "b0ef969032882b1f7eb1c7571e313214baa1485f7b61cf35807b2434e254365c",
"https://deno.land/std@0.85.0/async/deferred.ts": "f89ed49ba5e1dd0227c6bd5b23f017be46c3f92e4f0338dda08ff5aa54b9f6c9",
"https://deno.land/std@0.85.0/async/delay.ts": "9de1d8d07d1927767ab7f82434b883f3d8294fb19cad819691a2ad81a728cf3d",
"https://deno.land/std@0.85.0/async/mod.ts": "253b41c658d768613eacfb11caa0a9ca7148442f932018a45576f7f27554c853",
Expand Down Expand Up @@ -546,6 +546,6 @@
"https://deno.land/x/zod@v3.14.4/index.ts": "035a7422d9f2be54daa0fe464254b69225b443000673e4794095d672471e8792",
"https://deno.land/x/zod@v3.14.4/mod.ts": "64e55237cb4410e17d968cd08975566059f27638ebb0b86048031b987ba251c4",
"https://deno.land/x/zod@v3.14.4/types.ts": "7829a9fe28910b928e13de4b1b7ae72798ab09934daf69f3ef9d7ce52d0d5663",
"https://esm.sh/ts-pattern@3.3.5": "13920cf5529bab1debc7df1be8bc57d914bf2d80cd81c452df8045af0da67f2d",
"https://esm.sh/ts-pattern@3.3.5": "68b836c71a4de8d4b55fd8469d517ab80bb4cc7969a8db6ad25f9fe5b15815bf",
"https://raw.githubusercontent.com/mweichert/clipboard/master/mod.ts": "6368780ee65d9f034a23b7d525229947e02f141a16f1678f2b25735f391a2c6e"
}
4 changes: 2 additions & 2 deletions npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as InstalledPlugin from '@taqueria/protocol/InstalledPlugin';
import * as LoadedConfig from '@taqueria/protocol/LoadedConfig';
import * as SanitizedAbsPath from '@taqueria/protocol/SanitizedAbsPath';
import * as TaqError from '@taqueria/protocol/TaqError';
import { chain, chainRej, map, mapRej } from 'fluture';
import { chain, chainRej, FutureInstance as Future, map, mapRej } from 'fluture';
import { pipe } from 'https://deno.land/x/fun@v1.0.0/fns.ts';
import { getConfig } from './taqueria-config.ts';
import * as utils from './taqueria-utils/taqueria-utils.ts';
Expand Down Expand Up @@ -90,7 +90,7 @@ const addToPluginList = (pluginName: NpmPluginName, loadedConfig: LoadedConfig.t
chain(writeJsonFile(loadedConfig.configFile)),
);

export const installPlugin = (projectDir: SanitizedAbsPath.t, i18n: i18n, plugin: string) =>
export const installPlugin = (projectDir: SanitizedAbsPath.t, i18n: i18n, plugin: string): Future<TaqError.t, string> =>
pipe(
requireNPM(projectDir, i18n),
chain(_ => exec('npm install -D <%= it.plugin %>', { plugin }, false, projectDir)),
Expand Down
Loading

0 comments on commit 83767fd

Please sign in to comment.