Comparing version 1.1.2-dev.20211115.4 to 1.1.2-dev.20230324.1
@@ -1,47 +0,8 @@ | ||
# TODO / Agile Board | ||
<details> | ||
<summary>LEGEND</summary> | ||
**Prioritization:** | ||
<img src="./assets/defcon-levels.jpeg" align="right"> | ||
DEFCON 1 = Critical | ||
DEFCON 2 = High | ||
DEFCON 3 = Medium | ||
DEFCON 4 = Low | ||
DEFCON 5 = Very Low | ||
**Difficulty:** | ||
SP = Story Points (1-10) | ||
</details> | ||
## DEFCON 1 | ||
- Only cache hooks that are requested, then take from GitHub/put hooks in npmignore | ||
- <s>Create Contribution Docs and make a create-hook script</s> | ||
## DEFCON 2 | ||
- Add tsc watch to the API (8 SP) | ||
- Instead of writing over the tsconfig, create temp tsconfig and direct the tsc compiler to the temp config by modifying process args (7 SP) | ||
- Update documentation to show that developers have access to creating local hooks and using hooks from urls (1 SP) | ||
## DEFCON 3 | ||
- Add documentation place for each hook and update create hook script (2 SP) | ||
- Add Babel to target lower version (4 SP) | ||
- Make tests run locally instead of needing a dev publish (7 SP) | ||
- Add arguments (4 SP) | ||
## DEFCON 4 | ||
- Only cache hooks that are requested, then take from GitHub/put hooks in npmignore (6 SP) | ||
- Add lintr (3 SP) | ||
- Add GitHub actions (2 SP) | ||
- Allow asynchronous calls (2 SP) | ||
## DEFCON 5 | ||
- Find a way to tell editors to ignore custom properties in tsconfig (9 SP) | ||
- Add lintr | ||
- Add GitHub actions | ||
- Allow asynchronous calls | ||
- Find a way to tell editors to ignore custom properties in tsconfig | ||
- Add Babel to target lower version | ||
- Add arguments |
@@ -1,30 +0,13 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const rootRegex = /^([^\/|\\])+/; | ||
let include, exclude; | ||
module.exports = { | ||
dependencies: [ 'glob' ], | ||
onInitCompilation(api) { | ||
const glob = require('glob'); | ||
const cwd = api.tsconfig.compilerOptions?.rootDir || api.tsconfig.directory; | ||
onInitCompilation: function(api) { | ||
// This will ensure the unsupported allowTs attribute is ignored | ||
api.tsconfig.ignore('compilerOptions.allowTs'); | ||
// Add included files from config | ||
const includedFiles = new Set(); | ||
for (const includedFromConfig of api.tsconfig.include || []) { | ||
const files = glob.sync(includedFromConfig, { cwd }); | ||
files.forEach(includedFiles.add.bind(includedFiles)); | ||
} | ||
// Save include and exclude files | ||
include = api.tsconfig.include ? [ ...api.tsconfig.include ] : []; | ||
exclude = api.tsconfig.exclude ? [ ...api.tsconfig.exclude ] : []; | ||
// Remove excluded files from config | ||
for (const excludedFromConfig of api.tsconfig.exclude || []) { | ||
const files = glob.sync(excludedFromConfig, { cwd }); | ||
files.forEach(includedFiles.delete.bind(includedFiles)); | ||
} | ||
// Register files to watch on change | ||
api.watch.apply(api, Array.from(includedFiles)); | ||
// Remove include and exclude files that aren't typescript from tsconfig for compilation | ||
@@ -40,43 +23,37 @@ api.tsconfig.include = api.tsconfig.include?.filter(file => file.endsWith('ts') || file.endsWith('*')); | ||
}, | ||
onWatchCompilation(event, file, api) { | ||
if (file.endsWith('js')) return; | ||
if (file.endsWith('ts') && !api.tsconfig?.compilerOptions?.allowTs) return; | ||
onPostCompilation: function(api) { | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const glob = require('glob'); | ||
const cwd = api.tsconfig?.compilerOptions?.rootDir || api.tsconfig.directory; | ||
const rootRegex = /^([^\/|\\])+/; | ||
const outDir = api.tsconfig?.compilerOptions?.outDir; | ||
const outFile = outDir ? file.replace(rootRegex, outDir) : file; | ||
switch(event) { | ||
case 'add': | ||
case 'change': | ||
fs.copyFileSync(file, outFile); | ||
break; | ||
case 'addDir': | ||
fs.mkdirSync(outFile, { recursive: true }); | ||
break; | ||
case 'unlink': | ||
case 'unklinkDir': | ||
fs.unlinkSync(outFile); | ||
break; | ||
// Add included files from config | ||
const includedFiles = new Set(); | ||
for (const includedFromConfig of include) { | ||
const files = glob.sync(includedFromConfig, { cwd }); | ||
for (const file of files) { | ||
includedFiles.add(file); | ||
} | ||
} | ||
}, | ||
onPostCompilation(api) { | ||
const outDir = api.tsconfig?.compilerOptions?.outDir; | ||
// Remove excluded files from config | ||
for (const excludedFromConfig of exclude) { | ||
const files = glob.sync(excludedFromConfig, { cwd }); | ||
for (const file of files) { | ||
includedFiles.delete(file); | ||
} | ||
} | ||
// Copy files to outDir | ||
for (const file of includedFiles) { | ||
const outFile = outDir ? file.replace(rootRegex, outDir) : file; | ||
if (!fs.lstatSync(file).isFile()) continue; | ||
if (file.endsWith('js')) continue; | ||
if (file.endsWith('ts') && !api.tsconfig?.compilerOptions?.allowTs) continue; | ||
const dir = path.dirname(outFile); | ||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir, { recursive: true }); | ||
if (fs.lstatSync(file).isDirectory()) { | ||
fs.mkdirSync(outFile, { recursive: true }); | ||
} else if (!file.endsWith('js') || !((file.endsWith('ts') || file.endsWith('tsx')) && !api.tsconfig?.compilerOptions?.allowTs)) { | ||
fs.copyFileSync(file, outFile); | ||
} | ||
fs.copyFileSync(file, outFile); | ||
} | ||
} | ||
} |
@@ -7,3 +7,2 @@ const fs = require('fs'); | ||
const installDependencies = require('./utils/installDependencies'); | ||
const watchDispatcher = require('./utils/watchDispatcher'); | ||
@@ -32,39 +31,27 @@ const tsconfigDir = process.cwd(); | ||
// Call each hook | ||
for (const hookModule of hookModules || []) { | ||
// Create TSC Hook API | ||
const ignoredConfigOptions = [ 'save', 'ignore', 'path', 'directory' ]; | ||
const watchedFiles = []; | ||
const api = { | ||
tsconfig: { | ||
...tsconfig, | ||
save() { | ||
const tsconfigCopy = JSON.parse(JSON.stringify(api.tsconfig)); | ||
for (const ignoredConfigOption of ignoredConfigOptions) { | ||
eval(`delete tsconfigCopy.${ignoredConfigOption}`); | ||
} | ||
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfigCopy, null, 2)); | ||
}, | ||
ignore(configOption) { | ||
ignoredConfigOptions.push(configOption); | ||
api.tsconfig.save(); | ||
}, | ||
path: tsconfigPath, | ||
directory: tsconfigDir | ||
// Create TSC Hook API | ||
const ignoredConfigOptions = [ 'save', 'ignore', 'path', 'directory' ]; | ||
const api = { | ||
tsconfig: { | ||
...tsconfig, | ||
save: function() { | ||
const tsconfigCopy = { ...api.tsconfig }; | ||
for (const ignoredConfigOption of ignoredConfigOptions) { | ||
eval(`delete tsconfigCopy.${ignoredConfigOption}`); | ||
} | ||
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfigCopy, null, 2)); | ||
}, | ||
watch(...files) { | ||
watchedFiles.push.apply(watchedFiles, files); | ||
} | ||
}; | ||
hookModule.onInitCompilation?.(api); | ||
if (hookModule.onWatchCompilation && /--watch|-w/.test(process.argv)) { | ||
watchDispatcher.add(watchedFiles); | ||
watchDispatcher.on('all', (event, path) => hookModule.onWatchCompilation(event, path, api)); | ||
ignore: function(configOption) { | ||
ignoredConfigOptions.push(configOption); | ||
api.tsconfig.save(); | ||
}, | ||
path: tsconfigPath, | ||
directory: tsconfigDir | ||
} | ||
}; | ||
if (hookModule.onPostCompilation) { | ||
process.on('exit', () => hookModule.onPostCompilation(api)); | ||
} | ||
// Call each hook | ||
for (const hookModule of hookModules || []) { | ||
hookModule?.onInitCompilation?.(api); | ||
process.on('exit', () => hookModule?.onPostCompilation?.(api)); | ||
} | ||
@@ -71,0 +58,0 @@ |
const { execSync } = require('child_process'); | ||
const path = require('path'); | ||
const md5 = require('./md5'); | ||
const crypto = require('crypto'); | ||
@@ -9,3 +9,3 @@ module.exports = function(hook, tsconfigDir) { | ||
new URL(hook); | ||
const hashPath = path.resolve(__dirname, '../hooks', `${md5(hook)}.js`); | ||
const hashPath = path.resolve(__dirname, '../hooks', `${crypto.createHash('md5').update(hook).digest('hex')}.js`); | ||
if (!fs.existsSync(hashPath)) { | ||
@@ -12,0 +12,0 @@ execSync(`curl ${hook} -o ${hashPath} -s`); |
{ | ||
"name": "tsc-hooks", | ||
"version": "1.1.2-dev.20211115.4", | ||
"version": "1.1.2-dev.20230324.1", | ||
"description": "Add tsc compiler hooks to your TypeScript project", | ||
@@ -15,6 +15,2 @@ "main": "run.js", | ||
], | ||
"injectionPaths": [ | ||
"typescript/bin/tsc", | ||
"@nestjs/cli/bin/nest.js" | ||
], | ||
"scripts": { | ||
@@ -29,10 +25,12 @@ "postinstall": "node run postinstall", | ||
"dependencies": { | ||
"chokidar": "^3.5.2", | ||
"json5": "^2.2.0", | ||
"typescript": "^4.3.2" | ||
"json5": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"chalk": "^4.1.2", | ||
"glob": "^7.1.7" | ||
"glob": "^7.1.7", | ||
"typescript": "^4.3.2 || ^5.0.2 " | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^4.3.2 || ^5.0.2 " | ||
} | ||
} |
const path = require('path'); | ||
const fs = require('fs'); | ||
const { injectionPaths } = require('./package.json'); | ||
const script = require(path.resolve(__dirname, 'scripts', process.argv[2])); | ||
if (script instanceof Function) { | ||
for (const injectionPath of injectionPaths) { | ||
const absoluteInjectionPath = path.resolve(process.cwd(), '../', injectionPath); | ||
if (fs.existsSync(absoluteInjectionPath)) { | ||
script(absoluteInjectionPath); | ||
} | ||
} | ||
script(path.resolve(process.cwd(), '../typescript/bin/tsc')); | ||
} |
const path = require('path'); | ||
const fs = require('fs'); | ||
module.exports = (BIN_PATH) => { | ||
module.exports = (TSC_BIN_PATH) => { | ||
const INJECTION_PATH = path.resolve(__dirname, '../lib/injection'); | ||
const BIN_FILE = fs.readFileSync(BIN_PATH, 'utf-8').split('\n'); | ||
const script = [ | ||
BIN_FILE.shift(), | ||
`require('${path.relative(path.dirname(BIN_PATH), INJECTION_PATH).replace(/\\/g, '/')}')`, | ||
...BIN_FILE | ||
'#!/usr/bin/env node', | ||
`require('${path.relative(path.dirname(TSC_BIN_PATH), INJECTION_PATH).replace(/\\/g, '/')}')`, | ||
"require('../lib/tsc.js')" | ||
]; | ||
fs.writeFileSync(BIN_PATH, script.join('\n')); | ||
fs.writeFileSync(TSC_BIN_PATH, script.join('\n')); | ||
} |
const fs = require('fs'); | ||
module.exports = (BIN_PATH) => { | ||
const BIN_FILE = fs.readFileSync(BIN_PATH, 'utf-8').split('\n'); | ||
BIN_FILE.splice(1, 1); | ||
fs.writeFileSync(BIN_PATH, BIN_FILE.join('\n')); | ||
module.exports = (TSC_BIN_PATH) => { | ||
fs.writeFileSync(TSC_BIN_PATH, "#!/usr/bin/env node\nrequire('../lib/tsc.js')\n"); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
12
115422
3
19
243
+ Addedtypescript@5.7.2(transitive)
- Removedchokidar@^3.5.2
- Removedtypescript@^4.3.2
- Removedanymatch@3.1.3(transitive)
- Removedbinary-extensions@2.3.0(transitive)
- Removedbraces@3.0.3(transitive)
- Removedchokidar@3.6.0(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedfsevents@2.3.3(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedis-binary-path@2.1.0(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removednormalize-path@3.0.0(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedreaddirp@3.6.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedtypescript@4.9.5(transitive)