Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build boot.js script using a build script #144

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Conversation

cdebost
Copy link
Collaborator

@cdebost cdebost commented Jan 30, 2019

This is a recovery of #43, which is part of the #130 architecture overhaul, and parts of #130 which improved on #43. I rebased it on top of master as best I could so we can review it and see if it's worth applying. The changes have been discussed and reviewed at length in #43.

The original description is below:

⚠️ This includes backward incompatible changes that impact Montage and Mop. Changes to those packages in the corresponding build branch must be coordinated and released in a future, backward-incompatible release. Some care will be needed to ensure that mop in particular depends on compatible versions of mr and montage.

This introduces a program, mrs, that can create stand-alone scripts from modules that only need the ability to produce and consume CommonJS modules with require and exports or module.exports, and depend only on a static working set. The resulting script has very little overhead and is based on the build products of Browserify.

mrs is sufficient to build mr/boot.js (previously bootstrap.js)from the CommonJS modules in the boot directory. Run npm run buildto produce a new revision of boot.js and boot/preload-boilerplate.js.

This aleviates the need to perform script injection in the bootstrapping process, at the expense of introducing a build step for the bootstrapper. This change also allows a greater level of code reuse between Mr and Montage in their bootstrapping processes. This also obviates the need to embed UMD boilerplate in these modules, since they will always be used as CommonJS modules, either as sources for the build or as instruments of Node.js.

Since mrs embeds the entirety of boot.js's dependencies, it is no longer necessary to use a subrepository for these dependencies and no longer necessary to use hard-coded relative locations for these dependencies in package.json. These dependencies may now be installed by NPM and the maintainers of Mr and its dependencies no longer need to coordinate or hard-code their dependency trees. This is important because Q will soon be breaking up into smaller modules and packages.

The mini-url module may now be a CommonJS module shared by Montage and Mr. Within Montage and Mr, it may be required by the name url. A mapping in package.json directs the module loader to use mini-url.js instead. On the Node.js side, where mini-url.js would not work, we fall back to Node.js's url module, which has an API that is a strict super-set of mini-url.js's.

Invert package nesting in browser boot: Previously, the root package was the module loader itself. Now, to match what is likely in practice, the application loads first, then the module loader, then promises.

@cdebost cdebost force-pushed the feature/build branch 5 times, most recently from d95a77f to 140a764 Compare January 30, 2019 20:10
⚠️ This includes backward incompatible changes that impact Montage and Mop.  Changes to those packages in the corresponding `build` branch must be coordinated and released in a future, backward-incompatible release.  Some care will be needed to ensure that `mop` in particular depends on compatible versions of `mr` and `montage`.

This introduces a program, `mrs`, that can create stand-alone scripts from modules that only need the ability to produce and consume CommonJS modules with `require` and `exports` or `module.exports`, and depend only on a static working set.  The resulting script has very little overhead and is based on the build products of Browserify.

`mrs` is sufficient to build `mr/boot.js` (previously `bootstrap.js`)from the CommonJS modules in the `boot` directory.  Run `npm run build`to produce a new revision of `boot.js` and `boot/preload-boilerplate.js`.

This aleviates the need to perform script injection in the bootstrapping process, at the expense of introducing a build step for the bootstrapper.  This change also allows a greater level of code reuse between Mr and Montage in their bootstrapping processes.  This also obviates the need to embed UMD boilerplate in these modules, since they will always be used as CommonJS modules, either as sources for the build or as instruments of Node.js.

Since `mrs` embeds the entirety of `boot.js`'s dependencies, it is no longer necessary to use a subrepository for these dependencies and no longer necessary to use hard-coded relative locations for these dependencies in `package.json`.  These dependencies may now be installed by NPM and the maintainers of Mr and its dependencies no longer need to coordinate or hard-code their dependency trees.  This is important because Q will soon be breaking up into smaller modules and packages.

The `mini-url` module may now be a CommonJS module shared by Montage and Mr.  Within Montage and Mr, it may be required by the name `url`.  A mapping in `package.json` directs the module loader to use `mini-url.js` instead.  On the Node.js side, where `mini-url.js` would not work, we fall back to Node.js's `url` module, which has an API that is a strict super-set of `mini-url.js`'s.

Invert package nesting in browser boot: Previously, the root package was the module loader itself.  Now, to match what is likely in practice, the application loads first, then the module loader, then promises.
If you can't beat 'em, join 'em.

Also, some Node.js/npm packages depend on this and we would like them to
work without modification, even if they're using bad nonstandard
variable names that shouldn't have been made in the first place.
Previously, each module descriptor shared the root package object.  This
made identity checks on the package object possible for test for package
equivalence, but `require.location` is a better practice anyway.  The
advantage of this new approach is that `module.require` is the same as
`require` and can be used to resolve module ids releative to the module.
kriskowal and others added 15 commits February 11, 2019 14:24
Restructured the module names to fit the Browserify model. The former
`require.js` has been renamed `common.js` which is augmented by both the
Node.js and browser adaptors. Loading `mr` or `mr/require` will give you
the interface appropriate for Node.js or the browser. The Node.js
interface stands in `require.js` but is redirected to `browser.js` for
client-side use.

The tests now run with Jasminum in Node.js and in the browser. Phandom
needs further study. However, there is a new Mr Jasminum boot script
that can run arbitrary Jasminum test modules in the same way Mr boots
normal CommonJS modules.

Jasmine and its now unnecessary promise awareness shim have been
scuttled.

The boilerplate for bootstrapping has been extended to expose
`module.bundle` to make it easy to inject already loaded or instantiated
modules from the bootstrapping process into the run-time. This may or
may not be desirable if the boot process use different, static versions
of those modules. In production, they should be consolidated.
Implement Mr Phantom
-   Missing preload module.
-   Incorrect require id for preload.
-   Script name not explicit in params reader.
The whole URL is cumbersome. Just use package name and module
identifier. Take care to ensure that the display name is a valid
JavaScript identifier, particularly if the package name starts with a
number.
By upgrading to latest Jasminum and accounting for the cyclic dependency
of Jasminum's PhantomJS runner upon Mr.
Addresses problems with finding "mr", just as "q", when they are
dependencies of the application package.
And use strict mode for builder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants