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

use export instead of the Javascript way #11

Merged
merged 1 commit into from
May 4, 2022
Merged

use export instead of the Javascript way #11

merged 1 commit into from
May 4, 2022

Conversation

Tei1988
Copy link
Contributor

@Tei1988 Tei1988 commented May 2, 2022

Hi,
I sent PR again.
I'm happy if you review this.

The error I met

In the case using TypeScript as a esbuild configuration language, an imported GasPlugin could not be resolved its type as Plugin.

import * as esbuild from 'esbuild'
import { GasPlugin } from 'esbuild-gas-plugin'

esbuild.build({
    entryPoints: ['src/main.ts'],
    bundle: true,
    outfile: 'dist/Code.gs',  
    plugins: [GasPlugin]
})

This code made an error like below:

% npm run build                 

> src@1.0.0 build
> ts-node ./esbuild.ts

/src/node_modules/ts-node/src/index.ts:820
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
esbuild.ts:2:10 - error TS2305: Module '"esbuild-gas-plugin"' has no exported member 'GasPlugin'.

2 import { GasPlugin } from 'esbuild-gas-plugin'
           ~~~~~~~~~

    at createTSError (/src/node_modules/ts-node/src/index.ts:820:12)
    at reportTSError (/src/node_modules/ts-node/src/index.ts:824:19)
    at getOutput (/src/node_modules/ts-node/src/index.ts:1014:36)
    at Object.compile (/src/node_modules/ts-node/src/index.ts:1322:43)
    at Module.m._compile (/src/node_modules/ts-node/src/index.ts:1454:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/src/node_modules/ts-node/src/index.ts:1458:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  diagnosticCodes: [ 2305 ]
}

Why this error occured?

I thought that tsc could not notice that GasPlugin is exported since the syntax esports.GasPlugin = GasPlugin is not for TypeScript but Javascript.

What does this PR change?

There are small changes in compiled files since I changed exports.GasPlugin = GasPlugin to export = { GasPlugin } in index.ts.

before:
dist/index.d.ts

export {}

dist/index.js

...
exports.GasPlugin = GasPlugin

after:
dist/index.d.ts

import type { Plugin } from 'esbuild';
declare const _default: {
    GasPlugin: Plugin;
};
export = _default;

dist/index.js

...

module.exports = { GasPlugin };

These changes makes be able to resolved GasPlugin as a Plugin for esbuild in TypeScript.
The usage is no changes.

import { GasPlugin } from 'esbuild-gas-plugin'

Copy link
Owner

@mahaker mahaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!
LGTM!

I'll release this feature.

@mahaker mahaker merged commit 3a1f2da into mahaker:main May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants