This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not cache require, require is already cached in NodeJS by des…
…ign (#194) * NodeJS caches the result of require calls in require.cache, building an additional caching layer (deps.ts) on top of that has no value and only breaks JS packaging tools such as webpack/rollup. * Ignore node/no-missing-require for deps.ts; the error is caused by eslint not detecting ts files as valid js modules.
- Loading branch information
Showing
1 changed file
with
16 additions
and
27 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 |
---|---|---|
@@ -1,56 +1,45 @@ | ||
const cache: any = {} | ||
|
||
function fetch(s: string) { | ||
if (!cache[s]) { | ||
cache[s] = require(s) | ||
} | ||
return cache[s] | ||
} | ||
|
||
export const deps = { | ||
/* eslint-disable node/no-missing-require */ | ||
export default { | ||
get stripAnsi(): (string: string) => string { | ||
return fetch('strip-ansi') | ||
return require('strip-ansi') | ||
}, | ||
get ansiStyles(): typeof import('ansi-styles') { | ||
return fetch('ansi-styles') | ||
return require('ansi-styles') | ||
}, | ||
get ansiEscapes(): any { | ||
return fetch('ansi-escapes') | ||
return require('ansi-escapes') | ||
}, | ||
get passwordPrompt(): any { | ||
return fetch('password-prompt') | ||
return require('password-prompt') | ||
}, | ||
get screen(): typeof import('@oclif/screen') { | ||
return fetch('@oclif/screen') | ||
return require('@oclif/screen') | ||
}, | ||
|
||
get open(): typeof import('./open').default { | ||
return fetch('./open').default | ||
return require('./open').default | ||
}, | ||
get prompt(): typeof import('./prompt') { | ||
return fetch('./prompt') | ||
return require('./prompt') | ||
}, | ||
get styledObject(): typeof import('./styled/object').default { | ||
return fetch('./styled/object').default | ||
return require('./styled/object').default | ||
}, | ||
get styledHeader(): typeof import('./styled/header').default { | ||
return fetch('./styled/header').default | ||
return require('./styled/header').default | ||
}, | ||
get styledJSON(): typeof import('./styled/json').default { | ||
return fetch('./styled/json').default | ||
return require('./styled/json').default | ||
}, | ||
get table(): typeof import('./styled/table').table { | ||
return fetch('./styled/table').table | ||
return require('./styled/table').table | ||
}, | ||
get tree(): typeof import('./styled/tree').default { | ||
return fetch('./styled/tree').default | ||
return require('./styled/tree').default | ||
}, | ||
get wait(): typeof import('./wait').default { | ||
return fetch('./wait').default | ||
return require('./wait').default | ||
}, | ||
get progress(): typeof import ('./styled/progress').default { | ||
return fetch('./styled/progress').default | ||
return require('./styled/progress').default | ||
}, | ||
} | ||
|
||
export default deps |