Skip to content

Commit

Permalink
Merge pull request #10771 from meteor/copy-directories-asynchronously
Browse files Browse the repository at this point in the history
Write files in Builder#_copyDirectory asynchronously.
  • Loading branch information
benjamn committed Nov 12, 2019
2 parents e0ddae2 + 61b2d17 commit 77a9784
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 117 deletions.
14 changes: 14 additions & 0 deletions tools/fs/files.ts
Expand Up @@ -1751,6 +1751,20 @@ export const unlink = wrapDestructiveFsFunc("unlink", fs.unlinkSync);
export const write = wrapFsFunc("write", fs.writeSync, []);
export const writeFile = wrapDestructiveFsFunc("writeFile", fs.writeFileSync);

// Asynchronous versions of some of the above functions.
export const promises = {
writeFile: wrapDestructiveFsFunc(
"promises.writeFile",
// TODO This will be easier with the fs.promises namespace (available
// in Node.js 12, in Meteor 1.9+).
(path, data, options) => new Promise((resolve, reject) => {
fs.writeFile(path, data, options, error => {
error ? reject(error) : resolve();
});
}),
),
};

type StatListener = (
current: Stats,
previous: Stats,
Expand Down
14 changes: 8 additions & 6 deletions tools/isobuild/builder.js
Expand Up @@ -545,9 +545,9 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}`
);
}

// Call this._copyDirectory rather than this.copyDirectory so that the
// Call this._copyDirectoryAsync rather than this.copyDirectory so the
// subBuilder hacks from Builder#enter won't apply a second time.
return this._copyDirectory(options);
return this._copyDirectoryAsync(options).await();
}

_ensureAllNonPackageDirectories(absFromDir, relToDir) {
Expand Down Expand Up @@ -598,10 +598,10 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}`
copyDirectory(options) {
// TODO(benjamn) Remove this wrapper when Builder#enter is no longer
// implemented using ridiculous hacks.
return this._copyDirectory(options);
return this._copyDirectoryAsync(options).await();
}

_copyDirectory({
_copyDirectoryAsync({
from, to,
ignore,
specificFiles,
Expand Down Expand Up @@ -763,7 +763,7 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}`
if (this.previousWrittenHashes[thisRelTo] !== hash) {
const content = optimisticReadFile(thisAbsFrom);

files.writeFile(
writePromises.push(files.promises.writeFile(
files.pathResolve(this.buildPath, thisRelTo),
// The reason we call files.writeFile here instead of
// files.copyFile is so that we can read the file using
Expand All @@ -776,7 +776,7 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}`
// this function is used by 'meteor create' which is copying from
// the read-only tools tree into a writable app."
{ mode: (fileStatus.mode & 0o100) ? 0o777 : 0o666 },
);
));
}

this.writtenHashes[thisRelTo] = hash;
Expand All @@ -785,7 +785,9 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}`
});
};

const writePromises = [];
walk(rootDir, to);
return Promise.all(writePromises);
}

// Returns a new Builder-compatible object that works just like a
Expand Down
@@ -0,0 +1,18 @@
# This file contains information which helps Meteor properly upgrade your
# app when you run 'meteor update'. You should check it into version control
# with your project.

notices-for-0.9.0
notices-for-0.9.1
0.9.4-platform-file
notices-for-facebook-graph-api-2
1.2.0-standard-minifiers-package
1.2.0-meteor-platform-split
1.2.0-cordova-changes
1.2.0-breaking-changes
1.3.0-split-minifiers-package
1.4.0-remove-old-dev-bundle-link
1.4.1-add-shell-server-package
1.4.3-split-account-service-packages
1.5-add-dynamic-import-package
1.7-split-underscore-from-meteor-base
Expand Up @@ -2,5 +2,10 @@
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
meteor-base
meteor-base@1.4.0
static-html
standard-minifier-css
standard-minifier-js
shell-server
dynamic-import
underscore
@@ -1 +1 @@
none
METEOR@1.8.1
108 changes: 55 additions & 53 deletions tools/tests/apps/compiler-plugin-static-html-error/.meteor/versions
@@ -1,53 +1,55 @@
autoupdate@1.2.2-plugins.0
babel-compiler@5.8.3-plugins.0_5
babel-runtime@0.1.2
base64@1.0.4-plugins.0
binary-heap@1.0.4-plugins.0
blaze@2.1.3-plugins.0
blaze-tools@1.0.4-plugins.0
boilerplate-generator@1.0.4-plugins.0
caching-compiler@1.0.0-plugins.1
caching-html-compiler@1.0.0
callback-hook@1.0.4-plugins.0
check@1.0.6-plugins.0
ddp@1.2.0-plugins.0
ddp-client@1.2.0-plugins.0
ddp-common@1.2.0-plugins.0
ddp-server@1.2.0-plugins.1
deps@1.0.8-plugins.0
diff-sequence@1.0.0-plugins.0
ecmascript@0.1.3-plugins.1
ejson@1.0.7-plugins.0
geojson-utils@1.0.4-plugins.0
html-tools@1.0.5-plugins.0
htmljs@1.0.5-plugins.0
http@1.1.1-plugins.0
id-map@1.0.4-plugins.0
jquery@1.11.3-plugins.0_3
json@1.0.4-plugins.0
logging@1.0.8-plugins.0
meteor@1.1.7-plugins.1
minifiers@1.1.6-plugins.0
minimongo@1.0.9-plugins.0
mongo@1.1.1-plugins.0
mongo-id@1.0.0-plugins.0
npm-mongo@1.4.32-plugins.0_1
observe-sequence@1.0.7-plugins.0
ordered-dict@1.0.4-plugins.0
promise@0.4.2-plugins.0
random@1.0.4-plugins.0
reactive-var@1.0.6-plugins.0
reload@1.1.4-plugins.0
retry@1.0.4-plugins.0
routepolicy@1.0.6-plugins.0
spacebars@1.0.7-plugins.0
spacebars-compiler@1.0.7-plugins.1
static-html@1.0.12
templating@1.1.2-plugins.1
templating-tools@0.0.1
tracker@1.0.8-plugins.0
ui@1.0.7-plugins.0
underscore@1.0.4-plugins.0
url@1.0.5-plugins.0
webapp@1.2.1-plugins.0
webapp-hashing@1.0.4-plugins.0
autoupdate@1.6.0
babel-compiler@7.3.4
babel-runtime@1.3.0
base64@1.0.12
blaze-tools@1.0.10
boilerplate-generator@1.6.0
caching-compiler@1.2.1
caching-html-compiler@1.1.3
callback-hook@1.1.0
check@1.3.1
ddp@1.4.0
ddp-client@2.3.3
ddp-common@1.4.0
ddp-server@2.3.0
deps@1.0.12
diff-sequence@1.1.1
dynamic-import@0.5.1
ecmascript@0.12.7
ecmascript-runtime@0.7.0
ecmascript-runtime-client@0.8.0
ecmascript-runtime-server@0.7.1
ejson@1.1.0
es5-shim@4.8.0
fetch@0.1.1
hot-code-push@1.0.4
html-tools@1.0.11
htmljs@1.0.11
id-map@1.1.0
inter-process-messaging@0.1.0
livedata@1.0.18
logging@1.1.20
meteor@1.9.3
meteor-base@1.4.0
minifier-css@1.4.2
minifier-js@2.4.1
modern-browsers@0.1.4
modules@0.13.0
modules-runtime@0.10.3
mongo-id@1.0.7
promise@0.11.2
random@1.1.0
reload@1.3.0
retry@1.1.0
routepolicy@1.1.0
shell-server@0.4.0
socket-stream-client@0.2.2
spacebars-compiler@1.1.3
standard-minifier-css@1.5.3
standard-minifier-js@2.4.1
static-html@1.2.2
templating-tools@1.1.2
tracker@1.2.0
underscore@1.0.10
webapp@1.7.4
webapp-hashing@1.0.9
@@ -0,0 +1,18 @@
# This file contains information which helps Meteor properly upgrade your
# app when you run 'meteor update'. You should check it into version control
# with your project.

notices-for-0.9.0
notices-for-0.9.1
0.9.4-platform-file
notices-for-facebook-graph-api-2
1.2.0-standard-minifiers-package
1.2.0-meteor-platform-split
1.2.0-cordova-changes
1.2.0-breaking-changes
1.3.0-split-minifiers-package
1.4.0-remove-old-dev-bundle-link
1.4.1-add-shell-server-package
1.4.3-split-account-service-packages
1.5-add-dynamic-import-package
1.7-split-underscore-from-meteor-base
Expand Up @@ -2,5 +2,10 @@
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
meteor-base
meteor-base@1.4.0
static-html
standard-minifier-css
standard-minifier-js
shell-server
dynamic-import
underscore
@@ -1 +1 @@
none
METEOR@1.8.1
108 changes: 55 additions & 53 deletions tools/tests/apps/compiler-plugin-static-html/.meteor/versions
@@ -1,53 +1,55 @@
autoupdate@1.2.2-plugins.0
babel-compiler@5.8.3-plugins.0_5
babel-runtime@0.1.2
base64@1.0.4-plugins.0
binary-heap@1.0.4-plugins.0
blaze@2.1.3-plugins.0
blaze-tools@1.0.4-plugins.0
boilerplate-generator@1.0.4-plugins.0
caching-compiler@1.0.0-plugins.1
caching-html-compiler@1.0.0
callback-hook@1.0.4-plugins.0
check@1.0.6-plugins.0
ddp@1.2.0-plugins.0
ddp-client@1.2.0-plugins.0
ddp-common@1.2.0-plugins.0
ddp-server@1.2.0-plugins.1
deps@1.0.8-plugins.0
diff-sequence@1.0.0-plugins.0
ecmascript@0.1.3-plugins.1
ejson@1.0.7-plugins.0
geojson-utils@1.0.4-plugins.0
html-tools@1.0.5-plugins.0
htmljs@1.0.5-plugins.0
http@1.1.1-plugins.0
id-map@1.0.4-plugins.0
jquery@1.11.3-plugins.0_3
json@1.0.4-plugins.0
logging@1.0.8-plugins.0
meteor@1.1.7-plugins.1
minifiers@1.1.6-plugins.0
minimongo@1.0.9-plugins.0
mongo@1.1.1-plugins.0
mongo-id@1.0.0-plugins.0
npm-mongo@1.4.32-plugins.0_1
observe-sequence@1.0.7-plugins.0
ordered-dict@1.0.4-plugins.0
promise@0.4.2-plugins.0
random@1.0.4-plugins.0
reactive-var@1.0.6-plugins.0
reload@1.1.4-plugins.0
retry@1.0.4-plugins.0
routepolicy@1.0.6-plugins.0
spacebars@1.0.7-plugins.0
spacebars-compiler@1.0.7-plugins.1
static-html@1.0.12
templating@1.1.2-plugins.1
templating-tools@0.0.1
tracker@1.0.8-plugins.0
ui@1.0.7-plugins.0
underscore@1.0.4-plugins.0
url@1.0.5-plugins.0
webapp@1.2.1-plugins.0
webapp-hashing@1.0.4-plugins.0
autoupdate@1.6.0
babel-compiler@7.3.4
babel-runtime@1.3.0
base64@1.0.12
blaze-tools@1.0.10
boilerplate-generator@1.6.0
caching-compiler@1.2.1
caching-html-compiler@1.1.3
callback-hook@1.1.0
check@1.3.1
ddp@1.4.0
ddp-client@2.3.3
ddp-common@1.4.0
ddp-server@2.3.0
deps@1.0.12
diff-sequence@1.1.1
dynamic-import@0.5.1
ecmascript@0.12.7
ecmascript-runtime@0.7.0
ecmascript-runtime-client@0.8.0
ecmascript-runtime-server@0.7.1
ejson@1.1.0
es5-shim@4.8.0
fetch@0.1.1
hot-code-push@1.0.4
html-tools@1.0.11
htmljs@1.0.11
id-map@1.1.0
inter-process-messaging@0.1.0
livedata@1.0.18
logging@1.1.20
meteor@1.9.3
meteor-base@1.4.0
minifier-css@1.4.2
minifier-js@2.4.1
modern-browsers@0.1.4
modules@0.13.0
modules-runtime@0.10.3
mongo-id@1.0.7
promise@0.11.2
random@1.1.0
reload@1.3.0
retry@1.1.0
routepolicy@1.1.0
shell-server@0.4.0
socket-stream-client@0.2.2
spacebars-compiler@1.1.3
standard-minifier-css@1.5.3
standard-minifier-js@2.4.1
static-html@1.2.2
templating-tools@1.1.2
tracker@1.2.0
underscore@1.0.10
webapp@1.7.4
webapp-hashing@1.0.9
3 changes: 2 additions & 1 deletion tools/tests/static-html.js
Expand Up @@ -54,7 +54,8 @@ selftest.define("static-html - throws error", () => {
s.cd('myapp');

const run = startRun(s);
run.matchBeforeExit("Attributes on <head> not supported");
run.match("Attributes on <head> not supported");
run.waitSecs(30);

run.stop();
});

0 comments on commit 77a9784

Please sign in to comment.