Skip to content

Commit

Permalink
Add ci yml, update typescript package and rename package name. (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar authored Dec 26, 2024
1 parent c0e47db commit 34d15f0
Show file tree
Hide file tree
Showing 22 changed files with 128 additions and 66 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish

on:
release:
types: [published]

jobs:
publish:
name: "Publish to npm registry"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.17.0'

- run: |
npm install -g pnpm
pnpm --version
npm ci
npm run build
npm test
- uses: JS-DevTools/npm-publish@4b07b26a2f6e0a51846e1870223e545bae91c552
if: github.event_name == 'release'
with:
token: ${{ secrets.NPM_PUBLISH_FOR_PUBLIC_REPO }}
registry: "https://registry.npmjs.org"
access: "public"

24 changes: 24 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: test
run-name: ${{ github.actor }} - test
on: [pull_request, push]
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.17.0'

- run: |
node --version
npm --version
npm install -g pnpm
pnpm --version
npm ci
npm run build
npm test
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
[![size][size]][size-url]
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)

This is a typescript rollup plugin forked from https://github.com/rollup/plugins/tree/master/packages/typescript .

We did some changes:

- Depends on a modified version of `typescript` npm package (`@cocos/typescript`)
- Renames the current package to `@cocos/rollup-plugin-typescript`

The original README is below:

# @rollup/plugin-typescript

🍣 A Rollup plugin for seamless integration between Rollup and Typescript.
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@mycocos/rollup-plugin-typescript",
"name": "@cocos/rollup-plugin-typescript",
"version": "12.1.2-cocos.2",
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -65,7 +65,7 @@
"dependencies": {
"@rollup/pluginutils": "^5.1.0",
"resolve": "^1.22.1",
"@mycocos/typescript": "^4.9.5-cocos.1"
"@cocos/typescript": "^4.9.5-cocos.2"
},
"devDependencies": {
"@rollup/plugin-buble": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/customTransformers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BuilderProgram, CustomTransformers, Program, TypeChecker } from '@mycocos/typescript';
import type { BuilderProgram, CustomTransformers, Program, TypeChecker } from '@cocos/typescript';

import type { CustomTransformerFactories, TransformerStage, TransformerFactory } from '../types';
/**
Expand Down
4 changes: 2 additions & 2 deletions src/diagnostics/emit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PluginContext } from 'rollup';
import type typescript from '@mycocos/typescript';
import type { Diagnostic, DiagnosticReporter } from '@mycocos/typescript';
import type typescript from '@cocos/typescript';
import type { Diagnostic, DiagnosticReporter } from '@cocos/typescript';

import type { DiagnosticsHost } from './host';
import diagnosticToWarning from './toWarning';
Expand Down
4 changes: 2 additions & 2 deletions src/diagnostics/host.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type typescript from '@mycocos/typescript';
import type { CompilerOptions, FormatDiagnosticsHost } from '@mycocos/typescript';
import type typescript from '@cocos/typescript';
import type { CompilerOptions, FormatDiagnosticsHost } from '@cocos/typescript';

export interface DiagnosticsHost extends FormatDiagnosticsHost {
getCompilationSettings(): CompilerOptions;
Expand Down
6 changes: 3 additions & 3 deletions src/diagnostics/toWarning.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type typescript from '@mycocos/typescript';
import type { Diagnostic, FormatDiagnosticsHost } from '@mycocos/typescript';
import type typescript from '@cocos/typescript';
import type { Diagnostic, FormatDiagnosticsHost } from '@cocos/typescript';

// TODO Drop rollup@2 compatibility and use native RollupLog type instead
interface RollupLog {
Expand Down Expand Up @@ -27,7 +27,7 @@ export default function diagnosticToWarning(
// Build a Rollup warning object from the diagnostics object.
const warning: RollupLog = {
pluginCode,
message: `@mycocos/rollup-plugin-typescript ${pluginCode}: ${message}`
message: `@cocos/rollup-plugin-typescript ${pluginCode}: ${message}`
};

if (diagnostic.file) {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';
import { createFilter } from '@rollup/pluginutils';

import type { Plugin, SourceDescription } from 'rollup';
import type { Watch } from '@mycocos/typescript';
import type { Watch } from '@cocos/typescript';

import type { RollupTypescriptOptions } from '../types';

Expand Down Expand Up @@ -53,7 +53,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
let program: Watch<unknown> | null = null;

return {
name: '@mycocos/typescript',
name: '@cocos/typescript',

buildStart(rollupOptions) {
emitParsedOptionsErrors(ts, this, parsedOptions);
Expand Down
4 changes: 2 additions & 2 deletions src/moduleResolution.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type typescript from '@mycocos/typescript';
import type typescript from '@cocos/typescript';
import type {
ModuleResolutionHost,
ResolvedModuleFull,
ResolvedProjectReference,
ModuleKind
} from '@mycocos/typescript';
} from '@cocos/typescript';
import type { CreateFilter } from '@rollup/pluginutils';

import type { DiagnosticsHost } from './diagnostics/host';
Expand Down
4 changes: 2 additions & 2 deletions src/options/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { CompilerOptions } from '@mycocos/typescript';
import type { CompilerOptions } from '@cocos/typescript';

import type { PartialCompilerOptions } from '../../types';

export type { EnumCompilerOptions, JsonCompilerOptions } from '../../types';
export { PartialCompilerOptions };

/** Typescript compiler options */
export type { CompilerOptions } from '@mycocos/typescript';
export type { CompilerOptions } from '@cocos/typescript';

export const DEFAULT_COMPILER_OPTIONS: PartialCompilerOptions = {
module: 'esnext',
Expand Down
4 changes: 2 additions & 2 deletions src/options/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-param-reassign */
import { resolve } from 'path';

import type typescript from '@mycocos/typescript';
import type typescript from '@cocos/typescript';

import type { CompilerOptions, PartialCompilerOptions } from './interfaces';

Expand Down Expand Up @@ -58,7 +58,7 @@ export function normalizeCompilerOptions(ts: typeof typescript, compilerOptions:
// Invalid module type
const moduleType = ts.ModuleKind[compilerOptions.module];
throw new Error(
`@mycocos/rollup-plugin-typescript: The module kind should be 'ES2015', 'ESNext', 'node16' or 'nodenext', found: '${moduleType}'`
`@cocos/rollup-plugin-typescript: The module kind should be 'ES2015', 'ESNext', 'node16' or 'nodenext', found: '${moduleType}'`
);
}
default:
Expand Down
2 changes: 1 addition & 1 deletion src/options/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import defaultTs from '@mycocos/typescript';
import defaultTs from '@cocos/typescript';

import type { RollupTypescriptOptions, PartialCompilerOptions } from '../../types';
import { getTsLibPath } from '../tslib';
Expand Down
6 changes: 3 additions & 3 deletions src/options/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFileSync } from 'fs';
import { dirname, resolve } from 'path';

import type { PluginContext } from 'rollup';
import typescript from '@mycocos/typescript';
import typescript from '@cocos/typescript';
import type {
Diagnostic,
ExtendedConfigCacheEntry,
Expand All @@ -12,7 +12,7 @@ import type {
TypeAcquisition,
WatchDirectoryFlags,
WatchOptions
} from '@mycocos/typescript';
} from '@cocos/typescript';

import type { RollupTypescriptOptions } from '../../types';
import diagnosticToWarning from '../diagnostics/toWarning';
Expand Down Expand Up @@ -216,6 +216,6 @@ export function emitParsedOptionsErrors(
if (parsedOptions.errors.length > 0) {
parsedOptions.errors.forEach((error) => context.warn(diagnosticToWarning(ts, null, error)));

context.error(`@mycocos/rollup-plugin-typescript: Couldn't process compiler options`);
context.error(`@cocos/rollup-plugin-typescript: Couldn't process compiler options`);
}
}
16 changes: 8 additions & 8 deletions src/options/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export function validateSourceMap(
) {
if (compilerOptions.sourceMap && !outputOptions.sourcemap && !autoSetSourceMap) {
context.warn(
`@mycocos/rollup-plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.`
`@cocos/rollup-plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.`
);
} else if (!compilerOptions.sourceMap && outputOptions.sourcemap) {
context.warn(
`@mycocos/rollup-plugin-typescript: Typescript 'sourceMap' compiler option must be set to generate source maps.`
`@cocos/rollup-plugin-typescript: Typescript 'sourceMap' compiler option must be set to generate source maps.`
);
}
}
Expand All @@ -43,11 +43,11 @@ export function validatePaths(
) {
if (compilerOptions.out) {
context.error(
`@mycocos/rollup-plugin-typescript: Deprecated Typescript compiler option 'out' is not supported. Use 'outDir' instead.`
`@cocos/rollup-plugin-typescript: Deprecated Typescript compiler option 'out' is not supported. Use 'outDir' instead.`
);
} else if (compilerOptions.outFile) {
context.error(
`@mycocos/rollup-plugin-typescript: Typescript compiler option 'outFile' is not supported. Use 'outDir' instead.`
`@cocos/rollup-plugin-typescript: Typescript compiler option 'outFile' is not supported. Use 'outDir' instead.`
);
}

Expand All @@ -62,21 +62,21 @@ export function validatePaths(
const fromRollupDirToTs = relative(outputDir, compilerOptions[dirProperty]!);
if (fromRollupDirToTs.startsWith('..')) {
context.error(
`@mycocos/rollup-plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside Rollup 'dir' option.`
`@cocos/rollup-plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside Rollup 'dir' option.`
);
}
} else if (dirProperty === 'outDir') {
const fromTsDirToRollup = relative(compilerOptions[dirProperty]!, outputDir);
if (fromTsDirToRollup.startsWith('..')) {
context.error(
`@mycocos/rollup-plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside the same directory as the Rollup 'file' option.`
`@cocos/rollup-plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside the same directory as the Rollup 'file' option.`
);
}
} else {
const fromTsDirToRollup = relative(outputDir, compilerOptions[dirProperty]!);
if (fromTsDirToRollup.startsWith('..')) {
context.error(
`@mycocos/rollup-plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside the same directory as the Rollup 'file' option.`
`@cocos/rollup-plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside the same directory as the Rollup 'file' option.`
);
}
}
Expand All @@ -86,7 +86,7 @@ export function validatePaths(
if (compilerOptions.declaration || compilerOptions.declarationMap || compilerOptions.composite) {
if (DIRECTORY_PROPS.every((dirProperty) => !compilerOptions[dirProperty])) {
context.error(
`@mycocos/rollup-plugin-typescript: You are using one of Typescript's compiler options 'declaration', 'declarationMap' or 'composite'. ` +
`@cocos/rollup-plugin-typescript: You are using one of Typescript's compiler options 'declaration', 'declarationMap' or 'composite'. ` +
`In this case 'outDir' or 'declarationDir' must be specified to generate declaration files.`
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/outputFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as path from 'path';

import { promises as fs } from 'fs';

import type typescript from '@mycocos/typescript';
import type typescript from '@cocos/typescript';

import type { OutputOptions, PluginContext, SourceDescription } from 'rollup';
import type { ParsedCommandLine } from '@mycocos/typescript';
import type { ParsedCommandLine } from '@cocos/typescript';

import type TSCache from './tscache';

Expand Down Expand Up @@ -114,7 +114,7 @@ export async function emitFile(
// legal paths do not start with . nor .. : https://github.com/rollup/rollup/issues/3507#issuecomment-616495912
if (relativePath.startsWith('..')) {
if (outputToFilesystem == null) {
context.warn(`@mycocos/rollup-plugin-typescript: outputToFilesystem option is defaulting to true.`);
context.warn(`@cocos/rollup-plugin-typescript: outputToFilesystem option is defaulting to true.`);
}
if (outputToFilesystem !== false) {
await fs.mkdir(path.dirname(normalizedFilePath), { recursive: true });
Expand Down
4 changes: 2 additions & 2 deletions src/preflight.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PluginContext } from 'rollup';
import typescript from '@mycocos/typescript';
import typescript from '@cocos/typescript';

import type { TypeScriptConfig } from './options/tsconfig';
// import { resolveIdAsync } from './tslib';
Expand All @@ -12,7 +12,7 @@ interface PreflightOptions {
tslib: any;
}

const pluginName = '@mycocos/rollup-plugin-typescript';
const pluginName = '@cocos/rollup-plugin-typescript';
const moduleErrorMessage = `
${pluginName}: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a
"module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext"
Expand Down
4 changes: 2 additions & 2 deletions src/watchProgram.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PluginContext } from 'rollup';
import typescript from '@mycocos/typescript';
import typescript from '@cocos/typescript';
import type {
CustomTransformers,
Diagnostic,
Expand All @@ -9,7 +9,7 @@ import type {
WatchCompilerHostOfFilesAndCompilerOptions,
WatchStatusReporter,
WriteFileCallback
} from '@mycocos/typescript';
} from '@cocos/typescript';

import type { CustomTransformerFactories } from '../types';

Expand Down
Loading

0 comments on commit 34d15f0

Please sign in to comment.