Skip to content

Commit

Permalink
feat: add browser module main priority to generated umd bundles
Browse files Browse the repository at this point in the history
* use babelfiy transform esm->cjs in npm_umd_bundle
  • Loading branch information
Fabian Wiles authored and alexeagle committed Aug 15, 2019
1 parent 9e26856 commit 17cfac9
Show file tree
Hide file tree
Showing 87 changed files with 160,378 additions and 20,389 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ jobs:

- run: bazel test ... --test_tag_filters=-e2e,-examples

- store_artifacts:
path: dist/bin/release.tar.gz
destination: release.tar.gz

test_e2e:
<<: *job_defaults
resource_class: xlarge
Expand Down
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
.idea
rules_nodejs-*.tar.gz
dist
release
bazel-out
/e2e/*/bazel-*
/examples/*/bazel-*
/packages/*/bazel-*
node_modules
examples/vendored_node/node-v10.12.0-linux-x64
examples/vendored_node/node-v10.12.0-linux-x64.tar.xz
examples/vendored_node/yarn-v1.10.0
examples/vendored_node/yarn-v1.10.0.tar.gz
!/third_party/npm/node_modules
9 changes: 7 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ npm_package(
deps = [
"//third_party/github.com/bazelbuild/bazel:package_contents",
"//third_party/github.com/bazelbuild/bazel-skylib:package_contents",
"//third_party/github.com/browserify/browserify:package_contents",
"//third_party/github.com/buffer-from:package_contents",
"//third_party/github.com/inikulin/parse5:package_contents",
"//third_party/github.com/gjtorikian/isBinaryFile:package_contents",
"//third_party/github.com/jhermsmeier/browserify-named-amd:package_contents",
"//third_party/github.com/juanjoDiaz/removeNPMAbsolutePaths:package_contents",
"//third_party/github.com/source-map:package_contents",
"//third_party/github.com/source-map-support:package_contents",
"//third_party/npm/node_modules/@babel/core:package_contents",
"//third_party/npm/node_modules/@babel/plugin-transform-modules-commonjs:package_contents",
"//third_party/npm/node_modules/babelify:package_contents",
"//third_party/npm/node_modules/base64-js:package_contents",
"//third_party/npm/node_modules/browserify:package_contents",
"//third_party/npm/node_modules/ieee754:package_contents",
"//third_party/npm/node_modules/named-amd:package_contents",
"//internal:package_contents",
"//internal/bazel_integration_test:package_contents",
"//internal/common:package_contents",
Expand Down
19 changes: 18 additions & 1 deletion e2e/ts_devserver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@build_bazel_rules_nodejs//internal/npm_install:npm_umd_bundle.bzl", "npm_umd_bundle")
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
load("@npm_bazel_typescript//:index.bzl", "ts_devserver", "ts_library")

Expand All @@ -24,14 +25,30 @@ exports_files([
ts_library(
name = "app",
srcs = ["app.ts"],
deps = ["@npm//date-fns"],
deps = [
"@npm//date-fns",
"@npm//rxjs",
"@npm//typeorm",
],
)

# typeorm is a special case for npm_umd_bundle as we need to excluded
# the `react-native-sqlite-storage` dynamic require from the umd bundle
npm_umd_bundle(
name = "typeorm_umd",
package_name = "typeorm",
entry_point = "@npm//:node_modules/typeorm/browser/index.js",
excluded = ["react-native-sqlite-storage"],
package = "@npm//typeorm",
)

ts_devserver(
name = "devserver",
entry_module = "e2e_ts_devserver/app",
scripts = [
"@npm//date-fns:date-fns.umd.js",
"@npm//rxjs:rxjs.umd.js",
":typeorm.umd.js",
],
# We'll collect all the devmode JS sources from these TypeScript libraries
deps = [":app"],
Expand Down
47 changes: 42 additions & 5 deletions e2e/ts_devserver/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
import {format} from 'date-fns';
import {of} from 'rxjs';
import {Column, Entity, PrimaryGeneratedColumn} from 'typeorm';

const el: HTMLDivElement = document.createElement('div');
const date: string = format(new Date(2019, 4, 7), 'MMMM D, YYYY');
el.innerText = `Hello, TypeScript today is ${date}`;
el.className = 'ts1';
document.body.appendChild(el);
function appendText(text: string, className: string) {
const el: HTMLDivElement = document.createElement('div');
el.innerText = text;
el.className = className;
document.body.appendChild(el);
}

function testDateFns() {
const date: string = format(new Date(2019, 4, 7), 'MMMM D, YYYY');
appendText(`Hello, TypeScript today is ${date}`, 'ts1');
}


@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
firstName: string;
@Column()
lastName: string;
@Column()
isActive: boolean;
}

function testBrowserEntryPoint() {
// this script will throw if the browser entryPoint in typeorm wasn't resolved correctly
const user = new User();
user.firstName = 'foo';
appendText(`firstname: ${user.firstName}`, 'entrypoint-browser');
}

function testModuleEntryPoint() {
// rxjs uses the module entrypoint to resolve to some import/export
of('rxjs works with modules!').subscribe(value => appendText(String(value), 'entrypoint-module'))
}

testDateFns();
testBrowserEntryPoint();
testModuleEntryPoint();
12 changes: 12 additions & 0 deletions e2e/ts_devserver/app_e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@ describe('app', () => {
div.getText().then(t => expect(t).toEqual(`Hello, TypeScript today is May 7, 2019`));
done();
});

it('should display: firstname: foo', (done) => {
const div = element(by.css('div.entrypoint-browser'));
div.getText().then(t => expect(t).toEqual(`firstname: foo`));
done();
});

it('should display: rxjs works with modules!', (done) => {
const div = element(by.css('div.entrypoint-module'));
div.getText().then(t => expect(t).toEqual(`rxjs works with modules!`));
done();
});
});
2 changes: 2 additions & 0 deletions e2e/ts_devserver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"@types/node": "7.0.18",
"date-fns": "1.30.1",
"jasmine": "2.8.0",
"rxjs": "^6.5.2",
"typeorm": "^0.2.17",
"typescript": "2.7.x"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions e2e/ts_devserver/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"lib": ["es2015", "dom"]
}
}
Loading

0 comments on commit 17cfac9

Please sign in to comment.