Code Monkey home page Code Monkey logo

interoperability's Introduction

Interoperability

SWC based tool, helps to compile TypeScript code to ESM and CommonJS Interoperable modules.

Build Status NPM version Downloads

Usage

Just run build directory

npx inop src build

Use option -p to adjust package.json with following changes

{
  ...
  "type": "module",
  "main": "build/index.cjs",
  "module": "build/index.js",
  "types": "build/index.d.ts",
  "exports": {
    "require": "./build/index.cjs",
    "import": "./build/index.js"
  },
  "files": [ //list build directory and sources for sourceMap
    "build",
    "src/index.ts"
  ],
  ...
}

Use option -i to ignore specific patterns

npx inop src build -i __tests__ -i __mocks__

As for module declarations and typechecking use the following command, since swc does not support them yet

tsc --declaration --emitDeclarationOnly

Here is the recommended tsconfig.json

{
  "compilerOptions": {
    ...
    "target": "ESNext",
    "module": "NodeNext",
    "declaration": true,
    "esModuleInterop": true,
    "moduleResolution": "NodeNext",
    ...
  },
  ...
}

And jest config jest.config.js

export default {
  ...
  coverageProvider: 'v8',
  extensionsToTreatAsEsm: ['.ts'],
  moduleNameMapper: {
    '^(\\.{1,2}/.*)\\.js$': '$1',
  },
  transform: {
    '^.+\\.ts$': '@swc/jest',
  },
  ...
};

Help

Arguments:
  source                         source directory
  build                          build directory

Options:
  -V, --version                  output the version number
  -m, --match <match>            files match pattern (default: "**/*.ts")
  -s, --swcrc <swcrc>            swcrc path (default: ".swcrc")
  -i, --ignore [ignore...]       ignore patterns
  -p, --package                  adjust package.json according to main property
  --commonjs-ext [commonjs-ext]  file extension of CommonJS files (default: ".cjs")
  --esm-ext [esm-ext]            file extension of ESM files (default: ".js")
  --skip-commonjs                do not generate CommonJS files
  --skip-esm                     do not generate ESM files
  -h, --help                     display help for command

License

License Apache-2.0 Copyright (c) 2023-present Ivan Zakharchanka

interoperability's People

Contributors

3axap4ehko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.