Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Webpack + VFS = <3 #525

Merged
merged 16 commits into from
Mar 21, 2018
Merged

Webpack + VFS = <3 #525

merged 16 commits into from
Mar 21, 2018

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Mar 18, 2018

No description provided.

@hansl hansl force-pushed the vfs-webpack branch 2 times, most recently from e347e78 to a39684c Compare March 18, 2018 17:33
// TODO: fix webpack typings.
// tslint:disable-next-line:no-any
(webpackCompiler as any).inputFileSystem = new WebpackFileSystemHostAdapter(
new NodeJsSyncHost(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be using the this.context.host instead of a new one? Or at least one based on the that one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should. Sorry I'll fix it. I tried it and it was failing, so decided to focus on one error at a time. Since all paths are absolute not to the Host but to the file system, that's a deeper change in general.


readFile(path: string, callback: Callback<Buffer>): void {
const o = this._host.read(normalize('/' + path)).pipe(
map(content => new Buffer(content)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be mapped to string via virtualFs.fileBufferToString.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the webpack adapter wants to have node Buffers as a return, because it expects this to match the fs interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't know that. In the ngtools/webpack FS we return the string. Maybe that's broken there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not broken for source files. The only thing Webpack is doing is toString('utf-8'), which works for strings 🤷

}

readlink(path: string, callback: Callback<string>): void {
const err: NodeJS.ErrnoException = new Error('Not a symlink.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should support symlinks in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, at least as far as the host is concerned, symlinks were intentionally left out of the design.

We "support" them by having the Node*Host supports proper stats and you check them, but if you don't know which host comes in then you cannot know (and shouldn't IMO).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I don't have any usecase that needs them right now either.

}

readdir(path: string, callback: Callback<string[]>): void {
return this._doHostCall(this._host.list(normalize('/' + path)), callback);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will need to return the system paths instead of the normalized Paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe as input, but readdir returns fragments which do not contain slashes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

throw err;
}

purge(_changes?: string[] | string): void {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be implemented in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this should do for our own adapter. For a cache system you can clear the cache, but here I don't thikn there's anything to do. purge is optional on the real typings btw.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it off and see if there's any problem then.

@hansl hansl force-pushed the vfs-webpack branch 10 times, most recently from 07a9203 to c796862 Compare March 20, 2018 04:53
stat(_path: Path): Observable<Stats<{}>> | null {
return null;
// Some hosts may not support stat.
stat(path: Path): Observable<Stats<{}>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observable<Stats>?


return observableOf(this._cache.has(path) || this._isDir(path));
list(path: Path): Observable<PathFragment[]> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on this returning Observable<PathFragment> instead of the array. Would allow the consumer to operator on the stream of elements directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see Observable<X> here as a replacement of Promise<>. The contract is that these will always emit once and complete, or error out. I like the consistence of this interface too.

return new Observable(obs => {
// Create folders if necessary.
const _createDir = (path: Path) => {
if (fs.existsSync(getSystemPath(path))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a refactor for the future but for all the sync calls could we use the async versions with utils.promisify and convert and return the observabled promise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the async ones? The sync ones need to be sync.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Sorry for the confusion.


// TODO: fix webpack typings.
// tslint:disable-next-line:no-any
(webpackCompiler as any).inputFileSystem = new WebpackFileSystemHostAdapter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The watch file system will be unaffected and I don't think caching will be used. This webpack plugin is always applied before anything else: https://github.com/webpack/webpack/blob/master/lib/node/NodeEnvironmentPlugin.js
https://github.com/webpack/webpack/blob/master/lib/webpack.js#L34

@@ -56,29 +56,29 @@ export function gatherDiagnostics(
const tsProgram = program as ts.Program;
// Check syntactic diagnostics.
time(`${benchmarkLabel}.gatherDiagnostics.ts.getSyntacticDiagnostics`);
checkDiagnostics(tsProgram.getSyntacticDiagnostics);
checkDiagnostics(tsProgram.getSyntacticDiagnostics.bind(tsProgram));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

() => tsProgram.getSyntacticDiagnostics() ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that looks better imho.

@@ -87,6 +88,8 @@ export interface AngularCompilerPluginOptions {

// Use tsconfig to include path globs.
compilerOptions?: ts.CompilerOptions;

host: virtualFs.Host<fs.Stats>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional?

filipesilva
filipesilva previously approved these changes Mar 20, 2018
@hansl hansl force-pushed the vfs-webpack branch 2 times, most recently from c880b24 to 0bcf4f8 Compare March 21, 2018 04:47
@@ -31,7 +32,7 @@ export function runTargetSpec(
host: TestProjectHost,
targetSpec: TargetSpecifier,
overrides = {},
logger: logging.Logger = new logging.NullLogger(),
logger: logging.Logger = createConsoleLogger(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be reverted.

@filipesilva
Copy link
Contributor

I will followup this PR with fixes for the Windows CI.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants