Skip to content

Commit

Permalink
Fix some type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Apr 25, 2023
1 parent fda79bc commit 6edc9eb
Show file tree
Hide file tree
Showing 48 changed files with 91 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/rollup/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ export type InputPluginOption = MaybePromise<Plugin | NullValue | false | InputP

export interface InputOptions {
acorn?: Record<string, unknown>;
acornInjectPlugins?: (() => unknown)[] | (() => unknown);
acornInjectPlugins?: ((...arguments_: any[]) => unknown)[] | ((...arguments_: any[]) => unknown);
cache?: boolean | RollupCache;
context?: string;
experimentalCacheExpiry?: number;
Expand Down
2 changes: 1 addition & 1 deletion test/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const fixturify = require('fixturify');
/**
* @type {import('../../src/rollup/types')} Rollup
*/
// @ts-expect-error cast to Rollup
const { rollup } = require('../../browser/dist/rollup.browser.js');
const { assertFilesAreEqual, runTestSuiteWithSamples, compareError } = require('../utils.js');

Expand Down Expand Up @@ -68,6 +67,7 @@ runTestSuiteWithSamples('browser', resolve(__dirname, 'samples'), (directory, co
});

function assertOutputMatches(output, directory) {
/** @type any */
const actual = {};
for (const file of output) {
const filePath = file.fileName.split('/');
Expand Down
1 change: 1 addition & 0 deletions test/browser/samples/missing-load/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = defineTest({
description: 'fails if a file cannot be loaded',
options: {
plugins: {
name: 'test',
resolveId(source) {
return source;
}
Expand Down
1 change: 1 addition & 0 deletions test/form/samples/absolute-path-resolver/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = defineTest({
options: {
plugins: [
{
name: 'test',
transform(code, id) {
if (/main/.test(id)) {
return code.replace('"./a.js"', JSON.stringify(path.resolve(__dirname, 'a.js')));
Expand Down
1 change: 0 additions & 1 deletion test/form/samples/addon-functions/_config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const assert = require('node:assert');
// @ts-expect-error export outside root
const { replaceDirectoryInStringifiedObject } = require('../../../utils');
const assertChunkData = chunk =>
assert.strictEqual(
Expand Down
3 changes: 3 additions & 0 deletions test/form/samples/banner-and-footer/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ module.exports = defineTest({
},
plugins: [
{
name: 'first',
banner: '/* first banner */',
footer() {
return '/* first footer */';
}
},
{
name: 'second',
banner() {
return '/* second banner */';
},
footer: '/* second footer */'
},
{
name: 'third',
banner() {
return Promise.resolve('/* 3rd banner */');
},
Expand Down
2 changes: 2 additions & 0 deletions test/form/samples/configure-file-url/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = defineTest({
options: {
plugins: [
{
name: 'first',
resolveId(id) {
if (id.endsWith('solved')) {
return id;
Expand Down Expand Up @@ -32,6 +33,7 @@ module.exports = defineTest({
}
},
{
name: 'second',
resolveFileUrl({ moduleId }) {
if (moduleId === 'resolved') {
return `'resolved'`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = defineTest({
interop: 'auto'
},
plugins: {
name: 'test',
renderDynamicImport() {
return { left: 'getIt(', right: ')' };
}
Expand Down
5 changes: 4 additions & 1 deletion test/form/samples/dynamic-import-unresolvable/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ module.exports = defineTest({
options: {
plugins: [
{
name: 'test',
resolveDynamicImport(specifier) {
if (specifier === './seven.js') {
return false;
}
assert.ok(specifier);
assert.strictEqual(typeof specifier, 'object');
if (typeof specifier !== 'object') {
throw new TypeError(`Unexpected specifier type ${typeof specifier}.`);
}
if (specifier.type === 'Literal') {
return "'./seven.js'";
}
Expand Down
9 changes: 7 additions & 2 deletions test/form/samples/emit-asset-file/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = defineTest({
description: 'supports emitting assets from plugin hooks',
options: {
plugins: {
name: 'test',
resolveId(id, importee) {
if (id.endsWith('.svg')) {
return path.resolve(path.dirname(importee), id);
Expand All @@ -26,9 +27,13 @@ module.exports = defineTest({
assert.strictEqual(keys[0], 'assets/logo-a2a2cdc4.svg');
const asset = outputBundle[keys[0]];
assert.strictEqual(asset.fileName, 'assets/logo-a2a2cdc4.svg');
assert.strictEqual(asset.type, 'asset');
if (asset.type !== 'asset') {
throw new Error(`Unexpected asset type ${asset.type}.`);
}
/** @type {any} */
const source = asset.source;
assert.ok(
asset.source.equals(readFileSync(path.resolve(__dirname, 'logo.svg'))),
source.equals(readFileSync(path.resolve(__dirname, 'logo.svg'))),
'asset has correct source'
);
assert.ok(keys[1].endsWith('.js'), `${keys[1]} ends with ".js"`);
Expand Down
1 change: 1 addition & 0 deletions test/form/samples/emit-file-tree-shaken-access/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = defineTest({
description: 'does not include format globals when tree-shaking an asset access',
options: {
plugins: {
name: 'test',
resolveId(id, importee) {
if (id.endsWith('.svg')) {
return path.resolve(path.dirname(importee), id);
Expand Down
1 change: 1 addition & 0 deletions test/form/samples/emit-uint8array-no-buffer/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = defineTest({
},
options: {
plugins: {
name: 'test',
resolveId(id) {
if (id.startsWith('asset')) {
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
transform(code, id) {
if (id.endsWith('synthetic.js')) {
return { syntheticNamedExports: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
transform(code, id) {
if (id.endsWith('synthetic.js')) {
return { syntheticNamedExports: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
transform() {
return { syntheticNamedExports: true };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
transform() {
return { syntheticNamedExports: true };
}
Expand Down
1 change: 1 addition & 0 deletions test/form/samples/generated-code-presets/es2015/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
renderStart(options) {
assert.strictEqual(options.generatedCode.arrowFunctions, true);
assert.strictEqual(options.generatedCode.objectShorthand, true);
Expand Down
1 change: 1 addition & 0 deletions test/form/samples/generated-code-presets/es5/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
renderStart(options) {
assert.strictEqual(options.generatedCode.arrowFunctions, false);
assert.strictEqual(options.generatedCode.objectShorthand, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
renderStart(options) {
assert.strictEqual(options.generatedCode.arrowFunctions, false);
assert.strictEqual(options.generatedCode.objectShorthand, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
transform(code, id) {
if (id.endsWith('synthetic.js')) {
return { syntheticNamedExports: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
transform(code, id) {
if (id.endsWith('synthetic.js')) {
return { syntheticNamedExports: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
transform() {
return { syntheticNamedExports: true };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
transform() {
return { syntheticNamedExports: true };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = defineTest({
description: 'handles special shapes of assertions',
expectedWarnings: 'UNRESOLVED_IMPORT',
options: {
external: () => true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
resolveDynamicImport(specifier) {
if (typeof specifier === 'object') {
if (specifier.type === 'TemplateLiteral') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = defineTest({
options: {
plugins: [
{
name: 'test',
resolveDynamicImport(specifier, importer, { assertions }) {
const resolutionOptions = {
external: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = defineTest({
output: { name: 'bundle' },
plugins: [
{
name: 'test',
resolveId(source, importer, { assertions, isEntry }) {
return {
id: source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = defineTest({
},
plugins: [
{
name: 'test',
resolveDynamicImport(specifier) {
if (typeof specifier === 'object') {
if (specifier.type === 'TemplateLiteral') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = defineTest({
external: id => id.startsWith('external'),
output: {
freeze: false,
/** @type any */
interop(id) {
return id.split('-')[1];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = defineTest({
external: id => id.startsWith('external'),
output: {
externalLiveBindings: false,
/** @type any */
interop(id) {
if (checkedIds.has(id)) {
throw new Error(`Interop for id ${id} has been requested twice.`);
Expand Down
1 change: 1 addition & 0 deletions test/form/samples/interop-per-dependency/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = defineTest({
options: {
external: id => id.startsWith('external'),
output: {
/** @type any*/
interop(id) {
if (id === null) {
return 'auto';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = defineTest({
options: {
external: id => id.startsWith('external'),
output: {
/** @type any */
interop(id) {
return id.split('-')[1];
},
Expand Down
4 changes: 4 additions & 0 deletions test/form/samples/intro-and-outro/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = defineTest({
external: ['external'],
plugins: [
{
name: 'first',
intro() {
return '// intro 1';
},
Expand All @@ -18,6 +19,7 @@ module.exports = defineTest({
}
},
{
name: 'second',
intro() {
return '// intro 2';
},
Expand All @@ -26,6 +28,7 @@ module.exports = defineTest({
}
},
{
name: 'third',
intro() {
return Promise.resolve('// intro 3');
},
Expand All @@ -34,6 +37,7 @@ module.exports = defineTest({
}
},
{
name: 'fourth',
intro: '// intro 4',
outro: '// outro 4'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = defineTest({
return true;
},
plugins: {
name: 'test',
async buildStart() {
// eslint-disable-next-line unicorn/consistent-function-scoping
const testExternal = async (source, expected) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = defineTest({
return true;
},
plugins: {
name: 'test',
async buildStart() {
// eslint-disable-next-line unicorn/consistent-function-scoping
const testExternal = async (source, expected) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = defineTest({
return true;
},
plugins: {
name: 'test',
async buildStart() {
// eslint-disable-next-line unicorn/consistent-function-scoping
const testExternal = async (source, expected) =>
Expand Down
1 change: 1 addition & 0 deletions test/form/samples/merge-namespaces/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = defineTest({
external: ['external1', 'external2'],
plugins: [
{
name: 'test',
transform() {
return { syntheticNamedExports: '__synthetic' };
}
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/supports-es6-shim/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = defineTest({
treeshake: true,
plugins: [
require('@rollup/plugin-node-resolve').default(),
require('@rollup/plugin-commonjs')()
require('@rollup/plugin-commonjs').default()
]
}
});
1 change: 1 addition & 0 deletions test/form/samples/synthetic-named-exports/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = defineTest({
options: {
plugins: [
{
name: 'test',
resolveId(id) {
if (id.endsWith('dep1.js')) {
return id;
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/system-reexports/_config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = defineTest({
description: 'merges reexports in systemjs',
options: {
external: true,
external: () => true,
output: { format: 'system' }
}
});

0 comments on commit 6edc9eb

Please sign in to comment.