Skip to content

Commit

Permalink
feat: update rollup to version 1.6+
Browse files Browse the repository at this point in the history
Closes #1227
  • Loading branch information
alan-agius4 committed Mar 12, 2019
1 parent 1aba9be commit 82f97e4
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 52 deletions.
6 changes: 3 additions & 3 deletions integration/samples/core/specs/sourcemaps.ts
Expand Up @@ -48,10 +48,10 @@ describe(`@sample/core`, () => {
});

it(`should reference each 'sources' path with a common prefix`, () => {
const everyUeveryMe = (sourceMap.sources as string[])
.filter(fileName => fileName !== 'null' && !fileName.startsWith('node_modules'))
const sourceMapPaths = (sourceMap.sources as string[])
.filter(fileName => fileName !== 'null' && !fileName.includes('node_modules'))
.every(fileName => fileName.startsWith('ng://@sample/core') && fileName.endsWith('.ts'));
expect(everyUeveryMe).to.be.true;
expect(sourceMapPaths).to.be.true;
});
});
});
4 changes: 2 additions & 2 deletions integration/samples/secondary/specs/ep-feature-a.ts
Expand Up @@ -18,11 +18,11 @@ describe(`@sample/secondary/feature-a`, () => {
});

it(`should register as 'global.sample.secondary[feature-a]' on global scope (UMD)`, () => {
expect(UMD_BUNDLE_CONTENTS).to.contain(`global.sample.secondary['feature-a'] = {}`);
expect(UMD_BUNDLE_CONTENTS).to.contain(`global.sample.secondary[\'feature-a\'] = {}`);
});

it(`should resolve '@sample/secondary/shared' from global-scope (UMD)`, () => {
expect(UMD_BUNDLE_CONTENTS).to.contain(`),global.sample.secondary.shared)`);
expect(UMD_BUNDLE_CONTENTS).to.contain(`), global.sample.secondary.shared)`);
});

it(`should 'require('@sample/secondary/shared')' from factory (UMD)`, () => {
Expand Down
4 changes: 2 additions & 2 deletions integration/samples/secondary/specs/ep-feature-b.ts
Expand Up @@ -18,11 +18,11 @@ describe(`@sample/secondary/feature-b`, () => {
});

it(`should register as 'global.sample.secondary[feature-b]' on global scope (UMD)`, () => {
expect(UMD_BUNDLE_CONTENTS).to.contain(`global.sample.secondary['feature-b'] = {}`);
expect(UMD_BUNDLE_CONTENTS).to.contain(`global.sample.secondary[\'feature-b\'] = {}`);
});

it(`should resolve '@sample/secondary/feature-a' from global-scope (UMD)`, () => {
expect(UMD_BUNDLE_CONTENTS).to.contain(`),global.sample.secondary['feature-a'])`);
expect(UMD_BUNDLE_CONTENTS).to.contain(`), global.sample.secondary[\'feature-a\'])`);
});

it(`should 'require('@sample/secondary/feature-a')' from factory (UMD)`, () => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -46,10 +46,10 @@
"postcss-url": "^8.0.0",
"read-pkg-up": "^4.0.0",
"rimraf": "^2.6.1",
"rollup": "^0.67.0",
"rollup": "^1.6.0",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-sourcemaps": "^0.4.2",
"rxjs": "^6.0.0",
"stylus": "^0.54.5",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/flatten/flatten.ts
Expand Up @@ -30,7 +30,7 @@ export interface FlattenOpts {
dependencyList: DependencyList;
}

export async function flattenToFesm(opts: FlattenOpts): Promise<void[]> {
export async function flattenToFesm(opts: FlattenOpts): Promise<void> {
return rollupBundleFile({
moduleName: opts.esmModuleId,
entry: opts.entryFile,
Expand All @@ -41,7 +41,7 @@ export async function flattenToFesm(opts: FlattenOpts): Promise<void[]> {
});
}

export async function flattenToUmd(opts: FlattenOpts): Promise<void[]> {
export async function flattenToUmd(opts: FlattenOpts): Promise<void> {
return rollupBundleFile({
transform: downlevelCodeWithTsc,
moduleName: opts.umdModuleId,
Expand Down
46 changes: 19 additions & 27 deletions src/lib/flatten/rollup.ts
Expand Up @@ -3,12 +3,11 @@ import * as nodeResolve from 'rollup-plugin-node-resolve';
import * as sourcemaps from 'rollup-plugin-sourcemaps';
import * as commonJs from 'rollup-plugin-commonjs';
import * as rollupJson from 'rollup-plugin-json';
import * as path from 'path';
import * as log from '../util/log';
import { ExternalModuleIdStrategy, DependencyList } from './external-module-id-strategy';
import { umdModuleIdStrategy } from './umd-module-id-strategy';
import { TransformHook } from 'rollup';
import { outputFile, outputJson } from 'fs-extra';
import { ensureUnixPath } from '../util/path';

/**
* Options used in `ng-packagr` for writing flat bundle files.
Expand All @@ -28,7 +27,7 @@ export interface RollupOptions {
}

/** Runs rollup over the given entry file, writes a bundle file. */
export async function rollupBundleFile(opts: RollupOptions): Promise<void[]> {
export async function rollupBundleFile(opts: RollupOptions): Promise<void> {
log.debug(`rollup (v${rollup.VERSION}) ${opts.entry} to ${opts.dest} (${opts.format})`);

const externalModuleIdStrategy = new ExternalModuleIdStrategy(opts.format, opts.dependencyList);
Expand All @@ -55,38 +54,31 @@ export async function rollupBundleFile(opts: RollupOptions): Promise<void[]> {
});

// Output the bundle to disk
const sourcemapFullFile = `${opts.dest}.map`;
const sourcemapFile = path.basename(sourcemapFullFile);
const result = await bundle.generate({
await bundle.write({
name: opts.moduleName,
format: opts.format,
amd: opts.amd,
file: opts.dest,
banner: '',
globals: moduleId => umdModuleIdStrategy(moduleId, opts.umdModuleIds || {}),
sourcemap: true,
sourcemapFile
});

// relocate sourcemaps
result.map.sources = result.map.sources.map(sourcePath => {
if (!sourcePath) {
return sourcePath;
}
sourcemapPathTransform: (sourcePath: string) => {
sourcePath = ensureUnixPath(sourcePath);
// relocate sourcemaps
if (!sourcePath) {
return sourcePath;
}

// the replace here is because during the compilation one of the `/` gets lost sometimes
const mapRootUrl = opts.sourceRoot.replace('//', '/');
if (sourcePath.indexOf(mapRootUrl) > 0) {
return `${opts.sourceRoot}${sourcePath.substr(sourcePath.indexOf(mapRootUrl) + mapRootUrl.length)}`;
} else if (sourcePath.indexOf(opts.sourceRoot) > 0) {
return sourcePath.substr(sourcePath.indexOf(mapRootUrl));
} else {
return sourcePath;
// the replace here is because during the compilation one of the `/` gets lost sometimes
const sourceRoot = ensureUnixPath(opts.sourceRoot);
const mapRootUrl = sourceRoot.replace('//', '/');
if (sourcePath.indexOf(mapRootUrl) >= 0) {
return `${sourceRoot}${sourcePath.substr(sourcePath.indexOf(mapRootUrl) + mapRootUrl.length)}`;
} else if (sourcePath.indexOf(sourceRoot) >= 0) {
return sourcePath.substr(sourcePath.indexOf(mapRootUrl));
} else {
return sourcePath;
}
}
});

// rollup doesn't add a sourceMappingURL
// https://github.com/rollup/rollup/issues/121
result.code = `${result.code}\n//# sourceMappingURL=${sourcemapFile}`;
return Promise.all([outputJson(sourcemapFullFile, result.map), outputFile(opts.dest, result.code)]);
}
2 changes: 1 addition & 1 deletion src/lib/flatten/uglify.ts
@@ -1,4 +1,4 @@
import { minify } from 'uglify-js';
import { minify } from 'terser';
import { writeFile, readFile } from 'fs-extra';
import { basename } from 'path';
import { debug, warn } from './../util/log';
Expand Down
61 changes: 48 additions & 13 deletions yarn.lock
Expand Up @@ -371,6 +371,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.10.0.tgz#08eeb736ae678ccf9ca0922063f3a08795894ede"
integrity sha512-6Mb9+PPq9UzRpQrlPzZAbhEvodWDTnsIakddUAtSDpKYF6eu5zAdW31n8x7UZStvqGnDC7dCJnvU188ylv/Ytw==

"@types/node@^11.9.5":
version "11.11.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.11.0.tgz#070e9ce7c90e727aca0e0c14e470f9a93ffe9390"
integrity sha512-D5Rt+HXgEywr3RQJcGlZUCTCx1qVbCZpVk3/tOOA6spLNZdGm8BU+zRgdRYDoF1pO3RuXLxADzMrF903JlQXqg==

"@types/normalize-package-data@*":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
Expand Down Expand Up @@ -448,6 +453,11 @@ abbrev@1:
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==

acorn@^6.1.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.1.1.tgz#7d25ae05bb8ad1f9b699108e1094ecd7884adc1f"
integrity sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==

ajv@^5.1.0, ajv@^5.3.0:
version "5.5.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965"
Expand Down Expand Up @@ -4150,7 +4160,7 @@ path-key@^2.0.0, path-key@^2.0.1:
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=

path-parse@^1.0.5:
path-parse@^1.0.5, path-parse@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
Expand Down Expand Up @@ -4700,13 +4710,20 @@ resolve-url@^0.2.1:
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=

resolve@^1.1.6, resolve@^1.1.7, resolve@^1.5.0, resolve@^1.8.1:
resolve@^1.1.6, resolve@^1.1.7, resolve@^1.5.0:
version "1.8.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.8.1.tgz#82f1ec19a423ac1fbd080b0bab06ba36e84a7a26"
integrity sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==
dependencies:
path-parse "^1.0.5"

resolve@^1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.10.0.tgz#3bdaaeaf45cc07f375656dfd2e54ed0810b101ba"
integrity sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==
dependencies:
path-parse "^1.0.6"

resolve@~1.1.6:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
Expand Down Expand Up @@ -4741,14 +4758,14 @@ rollup-plugin-json@^3.1.0:
dependencies:
rollup-pluginutils "^2.3.1"

rollup-plugin-node-resolve@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-4.0.0.tgz#9bc6b8205e9936cc0e26bba2415f1ecf1e64d9b2"
integrity sha512-7Ni+/M5RPSUBfUaP9alwYQiIKnKeXCOHiqBpKUl9kwp3jX5ZJtgXAait1cne6pGEVUUztPD6skIKH9Kq9sNtfw==
rollup-plugin-node-resolve@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-4.0.1.tgz#f95765d174e5daeef9ea6268566141f53aa9d422"
integrity sha512-fSS7YDuCe0gYqKsr5OvxMloeZYUSgN43Ypi1WeRZzQcWtHgFayV5tUSPYpxuaioIIWaBXl6NrVk0T2/sKwueLg==
dependencies:
builtin-modules "^3.0.0"
is-module "^1.0.0"
resolve "^1.8.1"
resolve "^1.10.0"

rollup-plugin-sourcemaps@^0.4.2:
version "0.4.2"
Expand All @@ -4774,13 +4791,14 @@ rollup-pluginutils@^2.3.1:
estree-walker "^0.5.2"
micromatch "^2.3.11"

rollup@^0.67.0:
version "0.67.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.67.0.tgz#16d4f259c55224dded6408e7666b7731500797a3"
integrity sha512-p34buXxArhwv9ieTdHvdhdo65Cbig68s/Z8llbZuiX5e+3zCqnBF02Ck9IH0tECrmvvrJVMws32Ry84hTnS1Tw==
rollup@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-1.6.0.tgz#4329f4634718197c678d18491724d50d8b7ee76c"
integrity sha512-qu9iWyuiOxAuBM8cAwLuqPclYdarIpayrkfQB7aTGTiyYPbvx+qVF33sIznfq4bxZCiytQux/FvZieUBAXivCw==
dependencies:
"@types/estree" "0.0.39"
"@types/node" "*"
"@types/node" "^11.9.5"
acorn "^6.1.1"

run-node@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -5025,6 +5043,14 @@ source-map-support@^0.5.6:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-support@~0.5.9:
version "0.5.10"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.10.tgz#2214080bc9d51832511ee2bab96e3c2f9353120c"
integrity sha512-YfQ3tQFTK/yzlGJuX8pTwa4tifQj4QS2Mj7UegOu8jAz59MqIiMGPXxQhVQiIMNzayuUSF/jEuVnfFF5JqybmQ==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
Expand Down Expand Up @@ -5336,6 +5362,15 @@ term-size@^1.2.0:
dependencies:
execa "^0.7.0"

terser@^3.16.1:
version "3.16.1"
resolved "https://registry.yarnpkg.com/terser/-/terser-3.16.1.tgz#5b0dd4fa1ffd0b0b43c2493b2c364fd179160493"
integrity sha512-JDJjgleBROeek2iBcSNzOHLKsB/MdDf+E/BOAJ0Tk9r7p9/fVobfv7LMJ/g/k3v9SXdmjZnIlFd5nfn/Rt0Xow==
dependencies:
commander "~2.17.1"
source-map "~0.6.1"
source-map-support "~0.5.9"

text-encoding@^0.6.4:
version "0.6.4"
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
Expand Down Expand Up @@ -5507,7 +5542,7 @@ typescript@~3.2.2:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==

uglify-js@^3.0.7, uglify-js@^3.1.4:
uglify-js@^3.1.4:
version "3.4.9"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3"
integrity sha512-8CJsbKOtEbnJsTyv6LE6m6ZKniqMiFWmm9sRbopbkGs3gMPPfd3Fh8iIA4Ykv5MgaTbqHr4BaoGLJLZNhsrW1Q==
Expand Down

0 comments on commit 82f97e4

Please sign in to comment.