Commit Graph

58 Commits

Author SHA1 Message Date
Jan Dvorak
8ec9f0b7be meteor-babel => @meteorjs/babel 2021-05-07 19:43:37 +02:00
Filipe Névola
479c4de87a Merge pull request #10663 from jamesmillerburgess/npm-discards-ts 2021-01-15 14:53:54 -04:00
zodern
9421e76075 Remove optimisticRealpath 2020-02-24 22:03:18 -06:00
zodern
d734481abd Use optimisticRealpath when copying node_modules 2019-12-23 10:31:03 -06:00
Ben Newman
926cba9a77 Revert "Merge pull request #10771 from meteor/copy-directories-asynchronously"
This reverts commit 77a9784929, reversing
changes made to e0ddae2cc7.
2019-11-11 19:35:16 -05:00
Ben Newman
cf04e051e3 Write files in Builder#_copyDirectory asynchronously.
Using fs.writeFileSync in a serial style becomes especially costly when
we're writing a lot of files. In a recent profiling exercise I did on
Windows, nearly 80% of the time taken by Builder#_copyDirectory was spent
just closing the written files. By using the asynchronous fs.writeFile
function, we should be able to parallelize at least some of this work, and
await all the promises at the very end of copying the directory.
2019-11-11 17:26:03 -05:00
James Miller Burgess
ac24d0067d Convert npm-discards.js to TypeScript 2019-08-04 15:32:29 +09:00
Ben Newman
769337551e Convert tools/tool-env/profile.js to TypeScript.
Unfortunately, this conversion triggered an error due to one of the
shortcomings of the Babel implementation of TypeScript:

SyntaxError: /tools/tool-env/profile.ts: Namespace not marked type-only declare. Non-declarative namespaces are only supported experimentally in Babel. To enable and review caveats see: https://babeljs.io/docs/en/babel-plugin-transform-typescript
  278 | }
  279 |
> 280 | export namespace Profile {
      |                  ^
  281 |   export let enabled = !! process.env.METEOR_PROFILE;
  282 |
  283 |   export function time<TResult>(bucket: string, f: () => TResult) {
    at File.buildCodeFrameError (/Users/ben/meteor/dev_bundle/lib/node_modules/@babel/core/lib/transformation/file/file.js:261:12)
    at transpileNamespace (/Users/ben/meteor/dev_bundle/lib/node_modules/@babel/plugin-transform-typescript/lib/namespace.js:25:25)
    at PluginPass.TSModuleDeclaration (/Users/ben/meteor/dev_bundle/lib/node_modules/@babel/plugin-transform-typescript/lib/index.js:271:32)
    at newFn (/Users/ben/meteor/dev_bundle/lib/node_modules/@babel/traverse/lib/visitors.js:193:21)
    at NodePath._call (/Users/ben/meteor/dev_bundle/lib/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/Users/ben/meteor/dev_bundle/lib/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/Users/ben/meteor/dev_bundle/lib/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (/Users/ben/meteor/dev_bundle/lib/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitMultiple (/Users/ben/meteor/dev_bundle/lib/node_modules/@babel/traverse/lib/context.js:85:17)
    at TraversalContext.visit (/Users/ben/meteor/dev_bundle/lib/node_modules/@babel/traverse/lib/context.js:144:19)
2019-07-06 09:18:35 -04:00
Ben Newman
8958cbc5e9 Convert tools/fs/watch.js to TypeScript. 2019-07-05 17:50:20 -04:00
Ben Newman
528b549460 Convert tools/fs/optimistic.js to TypeScript. 2019-07-05 12:29:19 -04:00
Ben Newman
5ed64fb1db Remove explicit .js extension from tools/fs/files imports. 2019-07-04 10:32:09 -04:00
Ben Newman
4ff27f8a52 Use Builder#copyTranspiledModules to compile .js and .ts files with Babel. 2019-04-26 18:55:07 -04:00
Ben Newman
01f515e6b2 Inconsequential style tweaks. 2019-02-28 14:02:59 -05:00
zodern
aadbbfbd2b Clean up code. 2019-02-28 14:02:57 -05:00
zodern
29b6ca6483 Avoid unnecessary work if the file was already written. 2019-02-28 14:02:48 -05:00
zodern
ead0a6de1f Fix indentation 2019-01-17 16:12:15 -06:00
zodern
285e1b50c3 Clean up code 2019-01-16 22:16:51 -06:00
zodern
65bc2b0100 Fix reusing symlinks from initial build 2019-01-16 20:21:00 -06:00
zodern
e04c87adfe Clean up old symlinks 2019-01-01 12:08:35 -06:00
zodern
92f84293b5 Add caching to _copyDirectory
This is most noticible in copyNodeModulesDirectory, which is called many times during each server build.
2018-12-31 22:01:36 -06:00
zodern
e14ce5b908 Do not atomicallyRewriteFile when not building in place 2018-12-31 21:38:26 -06:00
Ben Newman
1a472a4161 Simplify external symlink handling in Builder#copyDirectory.
Follow-up to af51b816, which fixed #8005 by copying symlinks to external
directories as directories rather than trying to preserve the symlinks.

Issue #10177 revealed a flaw in this strategy: the filter function that we
use to strip development npm packages always rejects external paths, even
if the original symlink was found in a valid production npm package, and
thus its contents should be included in the production bundle.

In the process of fixing this problem, I realized that the only important
part of af51b816 was this code:

  // Update fileStatus to match the actual file rather than the
  // symbolic link, thus forcing the file to be copied below.
  fileStatus = optimisticLStatOrNull(externalPath);

and the code for manipulating thisAbsFrom and _currentRealRootDirectory
could be removed.
2018-09-05 21:30:27 -04:00
Ben Newman
f8c76b90dc Force .meteor/local/build to be rebuilt in-place on Windows.
Because in-place rebuilds are disabled by default on Windows, we were
losing .meteor/local/build/programs/web.browser.legacy every time we
rebuilt .meteor/local/build as part of writeSiteArchive, as reported by
@lmachens in this comment: https://github.com/meteor/meteor/pull/9942#issuecomment-406656741

In-place rewriting of .meteor/local/build seems essential for the new
strategy of writing different targets at different times, though I have
attempted to limit the risk of overwriting open files on Windows by
continuing to build the individual target directories from scratch (that
is, by writing a fresh temporary directory and then renaming it over the
existing directory).

Though I don't have any specific ideas in this direction, it may be worth
noting: if we could find a way to make in-place builds safer on Windows
(as they are on Linux and Mac), Windows rebuilds would be significantly
faster than they are with the current strategy of rewriting everything
from scratch every time.
2018-07-20 19:10:18 -04:00
Ben Newman
1b17025cd4 Tolerate missing files in Builder#_ensureDirectory.
Fixes #9882.
2018-05-12 11:40:01 -04:00
Ben Newman
c6c92255e5 Relax options.from precondition in Builder#copyNodeModulesDirectory. 2018-03-26 12:04:12 -04:00
Ben Newman
e7ad5d2a42 Call files.cp_r with { preserveSymlinks: true } in more places.
Now that symlinks can be used to enable selective compilation of
node_modules, it's important to preserve them.
2018-03-26 12:04:12 -04:00
Ben Newman
22e3f99565 Fix copying/symlinking of node_modules directories during build.
The bulk of this commit implements `builder.copyNodeModulesDirectory` to
allow more than one `node_modules` directory to be copied to the same
destination with as much safe symlinking as possible.

However, the crux of the fix for #9738 is the removal of the call to
`builder.generateFilename`, which deserves additional explanation.

If multiple directories are copied to the same output path by the builder,
in some cases it makes sense to ensure distinct directory names by adding
numeric suffixes to some of the directories.

In general, `builder.generateFilename` can get away with this renaming
only if the exact names of the directories are an implementation detail.

However, the code changed by this commit was altering the names of
`node_modules` directories whenever a package had both an `Npm.depends`
and a local `node_modules` directory.

Not only is it totally invalid to change the name of a `node_modules`
directory, but there is also no harm in copying the contents of multiple
`node_modules` directories into one final directory called `node_modules`.

Should fix #9738.
2018-03-23 18:59:32 -04:00
Ben Newman
352b319646 Allow Builder#copyDirectory to re-create symlinks again.
Commit 86ec7eb5db broke tests because we
rely on symlinks even when the symlink option is false.
2017-10-16 14:59:01 -04:00
Ben Newman
eded323039 Avoid calling files.stat(source) in symlinkWithOverwrite.
This was dangerous because source is often a path relative to the old
target file, whereas files.stat was interpreting source as a path relative
to process.cwd().

Fixes #9203.
2017-10-16 14:07:11 -04:00
Ben Newman
86ec7eb5db Avoid creating symlinks in Builder#copyDirectory when forbidden. 2017-10-16 14:07:07 -04:00
Ben Newman
6f925b0103 Merge branch 'devel' into release-1.6 2017-06-06 12:51:50 -04:00
Ben Newman
a2f26cbe6e Fix #8761 in three different ways.
The root of the problem was that the es5-ext npm package contains
directories called '#', e.g.
https://github.com/medikoo/es5-ext/tree/master/array/%23

These directory names were being sanitized to '' and thus ignored when
reserving paths in the Builder, which led to reservation conflicts later.

This commit fixes the problem in three different and independently
sufficient ways:

* Use files.mkdir_p instead of files.mkdir when creating parent
  directories of written files.

* Replace illegal characters in sanitized paths with '_' instead of ''.

* Allow '#' in sanitized paths (only needs to be escaped in the shell, not
  actually forbidden in paths).
2017-06-06 12:25:33 -04:00
Ben Newman
b3b464b614 Miscellaneous updates due to changes between Node 5 and 7.
https://github.com/nodejs/node/wiki/Breaking-changes-between-v5-and-v6
https://github.com/nodejs/node/wiki/Breaking-changes-between-v6-and-v7
2017-06-05 18:57:52 -04:00
Ben Newman
6418026e15 Update all new Buffer usage to Buffer.from for Node 6+.
https://github.com/nodejs/node/wiki/Breaking-changes-between-v5-and-v6
2017-06-05 18:16:03 -04:00
Hugh Willson
39748d82f1 Updated the builder whitelist to allow "@" in filenames. 2017-03-20 13:33:57 -04:00
Ben Newman
f42c137f55 Always copy node_modules/.bin into bundle/programs/server/npm.
Fixes #8136.
2016-12-06 10:16:43 -05:00
Ben Newman
a7ac32e00a Tolerate ENOENT errors in Builder#copyDirectory. 2016-11-08 13:33:20 -05:00
Ben Newman
ad460e0d7d Tolerate files.realpath throwing ELOOP exceptions. 2016-11-04 18:45:51 -04:00
Ben Newman
7f35e94713 Tolerate files.realpath throwing ENOENT exceptions. 2016-11-04 18:14:09 -04:00
Ben Newman
af51b8160c Use absolute paths for external symlinks in Builder#copyDirectory.
Thanks to @worldsayshi for reporting this issue with a reproduction.

Fixes #8005.
Fixes #2876.
Fixes #7154.
2016-11-04 17:44:42 -04:00
Ben Newman
1b3edb2300 Write files with appropriate mode in Builder#copyDirectory.
Fixes #7974.
2016-10-28 16:11:29 -04:00
Ben Newman
c572b12f26 Allow Builder#copyDirectory to make junction links on Windows. 2016-10-14 16:25:07 -04:00
Ben Newman
8e57ecb731 Use optimistic functions in Builder#copyDirectory. 2016-09-26 20:12:46 -04:00
Ben Newman
7574f74481 Avoid copying devDependencies from local node_modules directories.
Fixes #6750.
2016-05-16 20:49:02 -04:00
Ben Newman
992c27e716 Recreate symlinks in Builder#copyDirectory, even if !canSymlink.
According to the comment for the copyDirectory method, this was the
intended behavior before I changed it.
2016-03-09 11:52:08 -05:00
Ben Newman
b82f82e7da Revert "Follow symbolic links in builder.copyDirectory."
This reverts commit e6b33a2627.
2016-03-09 11:52:08 -05:00
Ben Newman
e6b33a2627 Follow symbolic links in builder.copyDirectory.
Fixes a blocking bug with the `meteor publish-release` command.
2016-03-08 22:48:48 -05:00
Ben Newman
99213da719 Make builder.copyDirectory symlink directory children. 2016-03-07 19:41:12 -05:00
David Greenspan
fabb20d2cd Rebuild in place for better performance
writeSiteArchive already supported rebuilding in place (rather than
creating a new build directory and moving it into place; see comments
at top of builder.js), but it was not used and didn't work:

* run-app.js only passed previousBuilders to the bundler in the case
  of a client-only refresh, in which case it also passed
  hasCachedBundle, bypassing writeSiteArchive altogether.

* writeSiteArchive's use of previousBuilders seemingly didn't work,
  because the site archive itself was never written in place, so
  trying to write the targets "in place" into a brand-new build
  directory didn't make sense (and threw an error).

With this change, previousBuilders are kept across all rebuilds
(not just client-only refreshes), which enables efficient, in-place
building (except on Windows, where in-place building has never been
supported), and writeSiteArchive is fixed to write the site archive
in place as well.
2016-02-04 17:11:39 -08:00
David Greenspan
f0b76186b5 Don't stat in Builder#write
The only reason for the files.stat in atomicallyRewriteFile (called
by Builder#write), which was taking up time comparable to write
and rename (not as much as one of those but same order of
magnitude, in the hundreds of ms total)... was for the case where we
are trying to rename a file in a way that overwrites an existing
directory.  We can avoid the stat by catching this unusual case when
rename throws an error.
2016-02-01 17:49:36 -08:00