Skip to content

Commit

Permalink
- object-hash hack optional #105
Browse files Browse the repository at this point in the history
  • Loading branch information
ezolenko committed Aug 14, 2018
1 parent 4d75522 commit 3b46e8d
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 32 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Must be before this plugin in the plugin list, especially when `browser: true` o

See explanation for `rollupCommonJSResolveHack` option below.

#### plugins using async/await

See `objectHashIgnoreUnknownHack` below.

### Plugin options

* `tsconfigDefaults`: `{}`
Expand Down Expand Up @@ -121,6 +125,10 @@ See explanation for `rollupCommonJSResolveHack` option below.

On windows typescript resolver favors POSIX path, while commonjs plugin (and maybe others?) uses native path as module id. This can result in `namedExports` being ignored if rollup happened to use typescript's resolution. Set to true to pass resolved module path through `resolve()` to match up with `rollup-plugin-commonjs`.

* `objectHashIgnoreUnknownHack`: false

The plugin uses rollup config as part of cache key. `object-hash` is used to generate a hash, but it can't hash certain elements at the moment. Setting this option to true will make `object-hash` ignore unknowns, at the cost of not invalidating the cache if ignored elements are changed. Only enable this if you need it (`Error: Unknown object type "asyncfunction"` for example) and make sure to run with `clean: true` once in a while and definitely before a release. (See [#105](https://github.com/ezolenko/rollup-plugin-typescript2/issues/105))

* `useTsconfigDeclarationDir`: false

If true, declaration files will be emitted in the directory given in the tsconfig. If false, the declaration files will be placed inside the destination directory given in the Rollup configuration.
Expand Down
2 changes: 1 addition & 1 deletion dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/ioptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ export interface IOptions {
transformers: TransformerFactoryCreator[];
tsconfigDefaults: any;
sourceMapCallback: (id: string, map: string) => void;
objectHashIgnoreUnknownHack: boolean;
}
//# sourceMappingURL=ioptions.d.ts.map
2 changes: 1 addition & 1 deletion dist/ioptions.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions dist/rollup-plugin-typescript2.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19691,23 +19691,24 @@ function convertDiagnostic(type, data) {
return entry;
});
}
const hashOptions = { algorithm: "sha1", ignoreUnknown: true };
class TsCache {
constructor(noCache, host, cache, options, rollupConfig, rootFilenames, context) {
constructor(noCache, hashIgnoreUnknown, host, cache, options, rollupConfig, rootFilenames, context) {
this.noCache = noCache;
this.host = host;
this.options = options;
this.rollupConfig = rollupConfig;
this.context = context;
this.cacheVersion = "7";
this.ambientTypesDirty = false;
this.hashOptions = { algorithm: "sha1", ignoreUnknown: false };
this.hashOptions.ignoreUnknown = hashIgnoreUnknown;
this.cacheDir = `${cache}/${objectHash_1({
version: this.cacheVersion,
rootFilenames,
options: this.options,
rollupConfig: this.rollupConfig,
tsVersion: tsModule.version,
}, hashOptions)}`;
}, this.hashOptions)}`;
this.dependencyTree = new graphlib_1({ directed: true });
this.dependencyTree.setDefaultNodeLabel((_node) => ({ dirty: false }));
const automaticTypes = lodash_7(tsModule.getAutomaticTypeDirectiveNames(options, tsModule.sys), (entry) => tsModule.resolveTypeReferenceDirective(entry, undefined, options, tsModule.sys))
Expand Down Expand Up @@ -19845,7 +19846,7 @@ class TsCache {
}
makeName(id, snapshot) {
const data = snapshot.getText(0, snapshot.getLength());
return objectHash_1({ data, id }, hashOptions);
return objectHash_1({ data, id }, this.hashOptions);
}
}

Expand Down Expand Up @@ -19991,7 +19992,7 @@ function typescript(options) {
let _cache;
const cache = () => {
if (!_cache)
_cache = new TsCache(pluginOptions.clean, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
_cache = new TsCache(pluginOptions.clean, pluginOptions.objectHashIgnoreUnknownHack, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
return _cache;
};
const pluginOptions = Object.assign({}, options);
Expand All @@ -20010,6 +20011,7 @@ function typescript(options) {
tsconfigOverride: {},
transformers: [],
tsconfigDefaults: {},
objectHashIgnoreUnknownHack: false,
});
setTypescriptModule(pluginOptions.typescript);
return {
Expand Down
2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.cjs.js.map

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions dist/rollup-plugin-typescript2.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -19687,23 +19687,24 @@ function convertDiagnostic(type, data) {
return entry;
});
}
const hashOptions = { algorithm: "sha1", ignoreUnknown: true };
class TsCache {
constructor(noCache, host, cache, options, rollupConfig, rootFilenames, context) {
constructor(noCache, hashIgnoreUnknown, host, cache, options, rollupConfig, rootFilenames, context) {
this.noCache = noCache;
this.host = host;
this.options = options;
this.rollupConfig = rollupConfig;
this.context = context;
this.cacheVersion = "7";
this.ambientTypesDirty = false;
this.hashOptions = { algorithm: "sha1", ignoreUnknown: false };
this.hashOptions.ignoreUnknown = hashIgnoreUnknown;
this.cacheDir = `${cache}/${objectHash_1({
version: this.cacheVersion,
rootFilenames,
options: this.options,
rollupConfig: this.rollupConfig,
tsVersion: tsModule.version,
}, hashOptions)}`;
}, this.hashOptions)}`;
this.dependencyTree = new graphlib_1({ directed: true });
this.dependencyTree.setDefaultNodeLabel((_node) => ({ dirty: false }));
const automaticTypes = lodash_7(tsModule.getAutomaticTypeDirectiveNames(options, tsModule.sys), (entry) => tsModule.resolveTypeReferenceDirective(entry, undefined, options, tsModule.sys))
Expand Down Expand Up @@ -19841,7 +19842,7 @@ class TsCache {
}
makeName(id, snapshot) {
const data = snapshot.getText(0, snapshot.getLength());
return objectHash_1({ data, id }, hashOptions);
return objectHash_1({ data, id }, this.hashOptions);
}
}

Expand Down Expand Up @@ -19987,7 +19988,7 @@ function typescript(options) {
let _cache;
const cache = () => {
if (!_cache)
_cache = new TsCache(pluginOptions.clean, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
_cache = new TsCache(pluginOptions.clean, pluginOptions.objectHashIgnoreUnknownHack, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
return _cache;
};
const pluginOptions = Object.assign({}, options);
Expand All @@ -20006,6 +20007,7 @@ function typescript(options) {
tsconfigOverride: {},
transformers: [],
tsconfigDefaults: {},
objectHashIgnoreUnknownHack: false,
});
setTypescriptModule(pluginOptions.typescript);
return {
Expand Down
2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.es.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/tscache.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export declare class TsCache {
private typesCache;
private semanticDiagnosticsCache;
private syntacticDiagnosticsCache;
constructor(noCache: boolean, host: tsTypes.LanguageServiceHost, cache: string, options: tsTypes.CompilerOptions, rollupConfig: any, rootFilenames: string[], context: IContext);
private hashOptions;
constructor(noCache: boolean, hashIgnoreUnknown: boolean, host: tsTypes.LanguageServiceHost, cache: string, options: tsTypes.CompilerOptions, rollupConfig: any, rootFilenames: string[], context: IContext);
clean(): void;
setDependency(importee: string, importer: string): void;
walkTree(cb: (id: string) => void | false): void;
Expand Down
2 changes: 1 addition & 1 deletion dist/tscache.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function typescript(options?: Partial<IOptions>)
const cache = (): TsCache =>
{
if (!_cache)
_cache = new TsCache(pluginOptions.clean, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
_cache = new TsCache(pluginOptions.clean, pluginOptions.objectHashIgnoreUnknownHack, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
return _cache;
};

Expand All @@ -58,6 +58,7 @@ export default function typescript(options?: Partial<IOptions>)
tsconfigOverride: {},
transformers: [],
tsconfigDefaults: {},
objectHashIgnoreUnknownHack: false,
});

setTypescriptModule(pluginOptions.typescript);
Expand Down
1 change: 1 addition & 0 deletions src/ioptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export interface IOptions
transformers: TransformerFactoryCreator[];
tsconfigDefaults: any;
sourceMapCallback: (id: string, map: string) => void;
objectHashIgnoreUnknownHack: boolean;
}
9 changes: 5 additions & 4 deletions src/tscache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export function convertDiagnostic(type: string, data: tsTypes.Diagnostic[]): IDi
});
}

const hashOptions = { algorithm: "sha1", ignoreUnknown: true };

export class TsCache
{
Expand All @@ -101,9 +100,11 @@ export class TsCache
private typesCache!: ICache<string>;
private semanticDiagnosticsCache!: ICache<IDiagnostics[]>;
private syntacticDiagnosticsCache!: ICache<IDiagnostics[]>;
private hashOptions = { algorithm: "sha1", ignoreUnknown: false };

constructor(private noCache: boolean, private host: tsTypes.LanguageServiceHost, cache: string, private options: tsTypes.CompilerOptions, private rollupConfig: any, rootFilenames: string[], private context: IContext)
constructor(private noCache: boolean, hashIgnoreUnknown: boolean, private host: tsTypes.LanguageServiceHost, cache: string, private options: tsTypes.CompilerOptions, private rollupConfig: any, rootFilenames: string[], private context: IContext)
{
this.hashOptions.ignoreUnknown = hashIgnoreUnknown;
this.cacheDir = `${cache}/${hash(
{
version: this.cacheVersion,
Expand All @@ -112,7 +113,7 @@ export class TsCache
rollupConfig: this.rollupConfig,
tsVersion: tsModule.version,
},
hashOptions
this.hashOptions
)}`;

this.dependencyTree = new Graph({ directed: true });
Expand Down Expand Up @@ -315,6 +316,6 @@ export class TsCache
private makeName(id: string, snapshot: tsTypes.IScriptSnapshot)
{
const data = snapshot.getText(0, snapshot.getLength());
return hash({ data, id }, hashOptions);
return hash({ data, id }, this.hashOptions);
}
}

0 comments on commit 3b46e8d

Please sign in to comment.