Skip to content

Commit afbe5e1

Browse files
authored
Merge pull request #14 from PolymerLabs/relative
Interpret paths relative to config file, fix some tsc/npm issues, release v0.1.1
2 parents ebdf0d4 + f97993d commit afbe5e1

File tree

6 files changed

+75
-40
lines changed

6 files changed

+75
-40
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
<!-- ## Unreleased -->
99

10+
## 0.1.1
11+
12+
- Interpret paths as relative to the location of the config file, instead of
13+
relative to the current working directory.
14+
15+
- Move `@types` packages from `dependencies` to `devDependencies` if they aren't
16+
part of any API. In particular, this fixes an error where any package that depended
17+
on `lit-localize` would need to add `DOM` to their TypeScript `lib` settings for
18+
compatibility with `@types/xmldom`.
19+
20+
- Publish `.d.ts` files.
21+
1022
## 0.1.0
1123

1224
- Initial release of `lit-localize`.

package-lock.json

+28-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
"prepack": "npm run build"
2727
},
2828
"dependencies": {
29-
"@types/jsonschema": "^1.1.1",
30-
"@types/minimist": "^1.2.0",
31-
"@types/node": "^13.13.4",
32-
"@types/parse5": "^5.0.2",
33-
"@types/xmldom": "^0.1.29",
3429
"jsonschema": "^1.2.6",
3530
"minimist": "^1.2.5",
3631
"parse5": "^6.0.0",
@@ -40,6 +35,11 @@
4035
"devDependencies": {
4136
"@types/diff": "^4.0.2",
4237
"@types/fs-extra": "^8.1.0",
38+
"@types/jsonschema": "^1.1.1",
39+
"@types/minimist": "^1.2.0",
40+
"@types/node": "^13.13.4",
41+
"@types/parse5": "^5.0.2",
42+
"@types/xmldom": "^0.1.29",
4343
"@typescript-eslint/eslint-plugin": "^2.30.0",
4444
"@typescript-eslint/parser": "^2.30.0",
4545
"ava": "^3.8.1",

src/cli.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {generateMsgModule, generateLocaleModule} from './module-generation';
1919
import {generateXlb, parseXlb} from './xlb';
2020
import {ProgramMessage} from './interfaces';
2121
import {KnownError} from './error';
22-
import {Config, readConfigFile, writeConfigSchemaIfMissing} from './config';
22+
import {Config, readConfigFileAndWriteSchema} from './config';
2323

2424
require('source-map-support').install();
2525

@@ -168,7 +168,6 @@ function configFromArgs(argv: string[]): Config {
168168
throw new KnownError(usage);
169169
}
170170
const configPath = args['config'] || './lit-localize.json';
171-
const config = readConfigFile(configPath);
172-
writeConfigSchemaIfMissing(config, configPath);
171+
const config = readConfigFileAndWriteSchema(configPath);
173172
return config;
174173
}

src/config.ts

+25-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import * as fs from 'fs';
1313
import * as jsonSchema from 'jsonschema';
14+
import * as pathLib from 'path';
1415
import {Locale} from './locales';
1516
import {KnownError} from './error';
1617

@@ -81,10 +82,11 @@ export interface Patch {
8182
}
8283

8384
/**
84-
* Read a JSON config file from the given path, validate it, and return it.
85-
* Throws if there was a problem reading, parsing, or validating.
85+
* Read a JSON config file from the given path, validate it, and return it. Also
86+
* adds a "$schema" property if missing. Throws if there was a problem reading,
87+
* parsing, or validating.
8688
*/
87-
export function readConfigFile(configPath: string): Config {
89+
export function readConfigFileAndWriteSchema(configPath: string): Config {
8890
let str;
8991
try {
9092
str = fs.readFileSync(configPath, 'utf8');
@@ -113,7 +115,25 @@ export function readConfigFile(configPath: string): Config {
113115
);
114116
}
115117

116-
return parsed as Config;
118+
const validated = parsed as Config;
119+
writeConfigSchemaIfMissing(validated, configPath);
120+
121+
// Interpret paths as relative to the config file rather than the current
122+
// working directory.
123+
const configFileRelativePath = (path: string) =>
124+
pathLib.relative(
125+
process.cwd(),
126+
pathLib.resolve(pathLib.dirname(configPath), path)
127+
);
128+
129+
const config = {
130+
...validated,
131+
tsConfig: configFileRelativePath(validated.tsConfig),
132+
xlbDir: configFileRelativePath(validated.xlbDir),
133+
tsOut: configFileRelativePath(validated.tsOut),
134+
};
135+
136+
return config;
117137
}
118138

119139
/**
@@ -123,7 +143,7 @@ export function readConfigFile(configPath: string): Config {
123143
* This $schema property allows editors like VSCode to provide validation and
124144
* auto-completion for the config format.
125145
*/
126-
export function writeConfigSchemaIfMissing(config: Config, configPath: string) {
146+
function writeConfigSchemaIfMissing(config: Config, configPath: string) {
127147
if ('$schema' in config) {
128148
return;
129149
}

tsconfig.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
"target": "es2018",
44
"module": "commonjs",
55
"moduleResolution": "node",
6+
"lib": ["es2018", "DOM"],
67
"strict": true,
78
"noUnusedLocals": true,
89
"noUnusedParameters": true,
910
"preserveConstEnums": true,
1011
"forceConsistentCasingInFileNames": true,
1112
"rootDir": "src/",
1213
"outDir": "lib/",
14+
"declaration": true,
1315
"sourceMap": true,
1416
"incremental": true,
1517
"tsBuildInfoFile": "lib/.tsbuildinfo"
1618
},
17-
"lib": [],
18-
"include": ["src/**/*"],
19-
"declaration": true,
20-
"pretty": true
19+
"include": ["src/**/*"]
2120
}

0 commit comments

Comments
 (0)