Files
Paul Gschwendtner 46045ad3fb refactor(bazel): add module interop for CJS/ESM compiler-cli package (#43431)
In the current Bazel setup, we run CommonJS as devmode output, and ESM
for prodmode output. This means that consumers of the
`@angular/bazel` package will end up using the prodmode-built ESM
package of the compiler-cli. This commit adds interop logic to be able
to load the compiler-cli as strict ESM package.

We cannot switch devmode to ESM, as this would require some changes
in `rules_nodejs` and potentially the reduction of both output flavors
into a single one (which is a future project anyway). This is out of
scope for now and inside g3, there is still devmode output as well.

PR Close #43431
2021-10-01 18:28:46 +00:00

45 lines
1.1 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as path from 'path';
import {setup} from './test_support';
describe('ngc_wrapped', () => {
it('should work', async () => {
const {read, write, runOneBuild, writeConfig, shouldExist, basePath, typesRoots} = setup();
write('some_project/index.ts', `
import {Component} from '@angular/core';
import {a} from 'ambient_module';
console.log('works: ', Component);
`);
const typesFile = path.resolve(basePath, typesRoots, 'thing', 'index.d.ts');
write(typesFile, `
declare module "ambient_module" {
declare const a = 1;
}
`);
writeConfig({
srcTargetPath: 'some_project',
depPaths: [path.dirname(typesFile)],
});
// expect no error
expect(await runOneBuild()).toBe(true);
shouldExist('bazel-bin/some_project/index.js');
expect(read('bazel-bin/some_project/index.js'))
.toContain(`console.log('works: ', core_1.Component);`);
});
});