Skip to content
Permalink
Browse files

Fix: Load latest versions from package in `create-hint` templates

Fix #2657
Close #2783
  • Loading branch information...
jaspreet57 authored and antross committed Aug 5, 2019
1 parent 93322e5 commit e84e4c9cdb0d07389759e6e88b0dea5bdaf3cb6c
@@ -12,6 +12,8 @@
"dependencies": {},
"description": "webhint's hint initializer package",
"devDependencies": {
"@hint/utils-tests-helpers": "^5.0.3",
"@types/debug": "^4.1.4",
"@typescript-eslint/eslint-plugin": "^1.13.0",
"@typescript-eslint/parser": "^1.12.0",
"@types/mkdirp": "^0.5.2",
@@ -1,23 +1,21 @@
import * as Handlebars from 'handlebars';

import { fs } from '@hint/utils';
import { utils } from 'hint';
import { loadCreateHintPackage } from './utils';

const { packages: { loadHintPackage } } = utils;
const { readFileAsync } = fs;

const pkg = loadHintPackage();
const pkg = loadCreateHintPackage();

/**
* Searches the current version used for a package in `hint` and uses that version or the `defaultVersion`.
* Searches package version in `create-hint/package.json` for given `packageName` and uses that version or the `defaultVersion`.
*
* It is recommended to add package as `devDependencies` in `create-hint/package.json` whenever new `package` is added to `package.hbs` template.
*
* This is used when creating a new hint via the CLI to make sure the dependencies are up-to-date in the moment
* of creation.
*/
Handlebars.registerHelper('dependencyVersion', (packageName, defaultVersion): string => {
const version = packageName === 'hint' ?
`^${pkg.version}` :
pkg.dependencies[packageName] ||
const version = pkg.dependencies[packageName] ||
pkg.devDependencies[packageName] ||
defaultVersion;

@@ -8,20 +8,20 @@
},
"description": "{{description}}",
"devDependencies": {
{{{dependencyVersion "@hint/utils-tests-helpers" "^2.0.3"}}},
{{{dependencyVersion "@types/debug" "0.0.31"}}},
{{{dependencyVersion "@types/node" "11.12.0"}}},
{{{dependencyVersion "@typescript-eslint/eslint-plugin" "^1.3.0"}}},
{{{dependencyVersion "@typescript-eslint/parser" "^1.3.0"}}},
{{{dependencyVersion "ava" "^1.2.0"}}},
{{{dependencyVersion "cpx" "^1.5.0"}}},
{{{dependencyVersion "eslint" "^5.13.0"}}},
{{{dependencyVersion "eslint-plugin-markdown" "^1.0.0"}}},
{{{dependencyVersion "npm-run-all" "^4.1.5"}}},
{{{dependencyVersion "nyc" "^13.1.0"}}},
{{{dependencyVersion "rimraf" "^2.6.3"}}},
{{{dependencyVersion "@hint/utils-tests-helpers"}}},
{{{dependencyVersion "@types/debug"}}},
{{{dependencyVersion "@types/node"}}},
{{{dependencyVersion "@typescript-eslint/eslint-plugin"}}},
{{{dependencyVersion "@typescript-eslint/parser"}}},
{{{dependencyVersion "ava"}}},
{{{dependencyVersion "cpx"}}},
{{{dependencyVersion "eslint"}}},
{{{dependencyVersion "eslint-plugin-markdown"}}},
{{{dependencyVersion "npm-run-all"}}},
{{{dependencyVersion "nyc"}}},
{{{dependencyVersion "rimraf"}}},
{{{dependencyVersion "hint"}}},
{{{dependencyVersion "typescript" "^3.3.1"}}}
{{{dependencyVersion "typescript"}}}
},
"engines": {
"node": ">=8.0.0"
@@ -0,0 +1,16 @@
import { packages } from '@hint/utils';

const { findPackageRoot } = packages;

/** Returns an object that represents the `package.json` version of `create-hint` */
export const loadCreateHintPackage = () => {
// webpack will embed the package.json
/* istanbul ignore if */
if (process.env.webpack) { // eslint-disable-line no-process-env
return require('../package.json');
}

const pkgRoot = findPackageRoot(__dirname, 'package.json');

return require(`${pkgRoot}/package.json`);
};

0 comments on commit e84e4c9

Please sign in to comment.
You can’t perform that action at this time.