diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a9b71ea..136a8e6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## 0.1.1 + +- Interpret paths as relative to the location of the config file, instead of + relative to the current working directory. + +- Move `@types` packages from `dependencies` to `devDependencies` if they aren't + part of any API. In particular, this fixes an error where any package that depended + on `lit-localize` would need to add `DOM` to their TypeScript `lib` settings for + compatibility with `@types/xmldom`. + +- Publish `.d.ts` files. + ## 0.1.0 - Initial release of `lit-localize`. diff --git a/package-lock.json b/package-lock.json index 8bc7be28..c5c59ae8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -194,6 +194,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/@types/jsonschema/-/jsonschema-1.1.1.tgz", "integrity": "sha1-CHA9/gdAEOjoKRIxEVlK9zH1exo=", + "dev": true, "requires": { "jsonschema": "*" } @@ -207,12 +208,14 @@ "@types/minimist": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=" + "integrity": "sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=", + "dev": true }, "@types/node": { "version": "13.13.4", "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.4.tgz", - "integrity": "sha512-x26ur3dSXgv5AwKS0lNfbjpCakGIduWU1DU91Zz58ONRWrIKGunmZBNv4P7N+e27sJkiGDsw/3fT4AtsqQBrBA==" + "integrity": "sha512-x26ur3dSXgv5AwKS0lNfbjpCakGIduWU1DU91Zz58ONRWrIKGunmZBNv4P7N+e27sJkiGDsw/3fT4AtsqQBrBA==", + "dev": true }, "@types/normalize-package-data": { "version": "2.4.0", @@ -223,53 +226,55 @@ "@types/parse5": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/@types/parse5/-/parse5-5.0.2.tgz", - "integrity": "sha512-BOl+6KDs4ItndUWUFchy3aEqGdHhw0BC4Uu+qoDonN/f0rbUnJbm71Ulj8Tt9jLFRaAxPLKvdS1bBLfx1qXR9g==" + "integrity": "sha512-BOl+6KDs4ItndUWUFchy3aEqGdHhw0BC4Uu+qoDonN/f0rbUnJbm71Ulj8Tt9jLFRaAxPLKvdS1bBLfx1qXR9g==", + "dev": true }, "@types/xmldom": { "version": "0.1.29", "resolved": "https://registry.npmjs.org/@types/xmldom/-/xmldom-0.1.29.tgz", - "integrity": "sha1-xEKLDKhtO4gUdXJv2UmAs4onw4E=" + "integrity": "sha1-xEKLDKhtO4gUdXJv2UmAs4onw4E=", + "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.30.0.tgz", - "integrity": "sha512-PGejii0qIZ9Q40RB2jIHyUpRWs1GJuHP1pkoCiaeicfwO9z7Fx03NQzupuyzAmv+q9/gFNHu7lo1ByMXe8PNyg==", + "version": "2.31.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.31.0.tgz", + "integrity": "sha512-iIC0Pb8qDaoit+m80Ln/aaeu9zKQdOLF4SHcGLarSeY1gurW6aU4JsOPMjKQwXlw70MvWKZQc6S2NamA8SJ/gg==", "dev": true, "requires": { - "@typescript-eslint/experimental-utils": "2.30.0", + "@typescript-eslint/experimental-utils": "2.31.0", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.0.0", "tsutils": "^3.17.1" } }, "@typescript-eslint/experimental-utils": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.30.0.tgz", - "integrity": "sha512-L3/tS9t+hAHksy8xuorhOzhdefN0ERPDWmR9CclsIGOUqGKy6tqc/P+SoXeJRye5gazkuPO0cK9MQRnolykzkA==", + "version": "2.31.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.31.0.tgz", + "integrity": "sha512-MI6IWkutLYQYTQgZ48IVnRXmLR/0Q6oAyJgiOror74arUMh7EWjJkADfirZhRsUMHeLJ85U2iySDwHTSnNi9vA==", "dev": true, "requires": { "@types/json-schema": "^7.0.3", - "@typescript-eslint/typescript-estree": "2.30.0", + "@typescript-eslint/typescript-estree": "2.31.0", "eslint-scope": "^5.0.0", "eslint-utils": "^2.0.0" } }, "@typescript-eslint/parser": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.30.0.tgz", - "integrity": "sha512-9kDOxzp0K85UnpmPJqUzdWaCNorYYgk1yZmf4IKzpeTlSAclnFsrLjfwD9mQExctLoLoGAUXq1co+fbr+3HeFw==", + "version": "2.31.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.31.0.tgz", + "integrity": "sha512-uph+w6xUOlyV2DLSC6o+fBDzZ5i7+3/TxAsH4h3eC64tlga57oMb96vVlXoMwjR/nN+xyWlsnxtbDkB46M2EPQ==", "dev": true, "requires": { "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "2.30.0", - "@typescript-eslint/typescript-estree": "2.30.0", + "@typescript-eslint/experimental-utils": "2.31.0", + "@typescript-eslint/typescript-estree": "2.31.0", "eslint-visitor-keys": "^1.1.0" } }, "@typescript-eslint/typescript-estree": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.30.0.tgz", - "integrity": "sha512-nI5WOechrA0qAhnr+DzqwmqHsx7Ulr/+0H7bWCcClDhhWkSyZR5BmTvnBEyONwJCTWHfc5PAQExX24VD26IAVw==", + "version": "2.31.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.31.0.tgz", + "integrity": "sha512-vxW149bXFXXuBrAak0eKHOzbcu9cvi6iNcJDzEtOkRwGHxJG15chiAQAwhLOsk+86p9GTr/TziYvw+H9kMaIgA==", "dev": true, "requires": { "debug": "^4.1.1", @@ -534,9 +539,9 @@ "dev": true }, "blueimp-md5": { - "version": "2.13.0", - "resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.13.0.tgz", - "integrity": "sha512-lmp0m647R5e77ORduxLW5mISIDcvgJZa52vMBv5uVI3UmSWTQjkJsZVBfaFqQPw/QFogJwvY6e3Gl9nP+Loe+Q==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.14.0.tgz", + "integrity": "sha512-fhX8JsIgugJ39g9MUJ4Y0S+WYd/1HATNVzW4nEVknP5uJU1mA7LZCV3OuVH9OvxpuYQXu6ttst0IYIlAyVfBQg==", "dev": true }, "boxen": { diff --git a/package.json b/package.json index a965fb9e..dff4af67 100644 --- a/package.json +++ b/package.json @@ -26,11 +26,6 @@ "prepack": "npm run build" }, "dependencies": { - "@types/jsonschema": "^1.1.1", - "@types/minimist": "^1.2.0", - "@types/node": "^13.13.4", - "@types/parse5": "^5.0.2", - "@types/xmldom": "^0.1.29", "jsonschema": "^1.2.6", "minimist": "^1.2.5", "parse5": "^6.0.0", @@ -40,6 +35,11 @@ "devDependencies": { "@types/diff": "^4.0.2", "@types/fs-extra": "^8.1.0", + "@types/jsonschema": "^1.1.1", + "@types/minimist": "^1.2.0", + "@types/node": "^13.13.4", + "@types/parse5": "^5.0.2", + "@types/xmldom": "^0.1.29", "@typescript-eslint/eslint-plugin": "^2.30.0", "@typescript-eslint/parser": "^2.30.0", "ava": "^3.8.1", diff --git a/src/cli.ts b/src/cli.ts index 5190380f..9abe063f 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -19,7 +19,7 @@ import {generateMsgModule, generateLocaleModule} from './module-generation'; import {generateXlb, parseXlb} from './xlb'; import {ProgramMessage} from './interfaces'; import {KnownError} from './error'; -import {Config, readConfigFile, writeConfigSchemaIfMissing} from './config'; +import {Config, readConfigFileAndWriteSchema} from './config'; require('source-map-support').install(); @@ -168,7 +168,6 @@ function configFromArgs(argv: string[]): Config { throw new KnownError(usage); } const configPath = args['config'] || './lit-localize.json'; - const config = readConfigFile(configPath); - writeConfigSchemaIfMissing(config, configPath); + const config = readConfigFileAndWriteSchema(configPath); return config; } diff --git a/src/config.ts b/src/config.ts index 073b3c05..b95bff35 100644 --- a/src/config.ts +++ b/src/config.ts @@ -11,6 +11,7 @@ import * as fs from 'fs'; import * as jsonSchema from 'jsonschema'; +import * as pathLib from 'path'; import {Locale} from './locales'; import {KnownError} from './error'; @@ -81,10 +82,11 @@ export interface Patch { } /** - * Read a JSON config file from the given path, validate it, and return it. - * Throws if there was a problem reading, parsing, or validating. + * Read a JSON config file from the given path, validate it, and return it. Also + * adds a "$schema" property if missing. Throws if there was a problem reading, + * parsing, or validating. */ -export function readConfigFile(configPath: string): Config { +export function readConfigFileAndWriteSchema(configPath: string): Config { let str; try { str = fs.readFileSync(configPath, 'utf8'); @@ -113,7 +115,25 @@ export function readConfigFile(configPath: string): Config { ); } - return parsed as Config; + const validated = parsed as Config; + writeConfigSchemaIfMissing(validated, configPath); + + // Interpret paths as relative to the config file rather than the current + // working directory. + const configFileRelativePath = (path: string) => + pathLib.relative( + process.cwd(), + pathLib.resolve(pathLib.dirname(configPath), path) + ); + + const config = { + ...validated, + tsConfig: configFileRelativePath(validated.tsConfig), + xlbDir: configFileRelativePath(validated.xlbDir), + tsOut: configFileRelativePath(validated.tsOut), + }; + + return config; } /** @@ -123,7 +143,7 @@ export function readConfigFile(configPath: string): Config { * This $schema property allows editors like VSCode to provide validation and * auto-completion for the config format. */ -export function writeConfigSchemaIfMissing(config: Config, configPath: string) { +function writeConfigSchemaIfMissing(config: Config, configPath: string) { if ('$schema' in config) { return; } diff --git a/tsconfig.json b/tsconfig.json index 4dcec7a0..cf9f1d5f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "target": "es2018", "module": "commonjs", "moduleResolution": "node", + "lib": ["es2018", "DOM"], "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, @@ -10,12 +11,10 @@ "forceConsistentCasingInFileNames": true, "rootDir": "src/", "outDir": "lib/", + "declaration": true, "sourceMap": true, "incremental": true, "tsBuildInfoFile": "lib/.tsbuildinfo" }, - "lib": [], - "include": ["src/**/*"], - "declaration": true, - "pretty": true + "include": ["src/**/*"] }