From 35d76a1cc06a36beebb37d4febf69af781268a71 Mon Sep 17 00:00:00 2001 From: Valerii Maslenykov Date: Thu, 15 Feb 2024 13:17:47 +0100 Subject: [PATCH] Add built Custom Elements into the npm package --- .eslintignore | 3 + .github/workflows/code-quality.yml | 4 + .github/workflows/deploy-demo.yml | 4 + .github/workflows/release.yml | 8 + .prettierignore | 3 + package.json | 3 +- packages/core/.gitignore | 4 +- packages/core/package.json | 44 +- packages/core/rollup.config.vanilla.js | 81 + .../core/src/lib/components/MisMerge2.svelte | 7 + .../core/src/lib/components/MisMerge3.svelte | 7 + .../core/src/lib/internal/blocks/added.ts | 2 +- .../src/lib/internal/blocks/merge-conflict.ts | 2 +- .../core/src/lib/internal/blocks/removed.ts | 2 +- packages/core/src/lib/internal/utils.ts | 2 +- pnpm-lock.yaml | 9845 +++++++++++++++++ 16 files changed, 10011 insertions(+), 10 deletions(-) create mode 100644 packages/core/rollup.config.vanilla.js create mode 100644 pnpm-lock.yaml diff --git a/.eslintignore b/.eslintignore index 7e13e77..ba05cee 100644 --- a/.eslintignore +++ b/.eslintignore @@ -12,3 +12,6 @@ package pnpm-lock.yaml package-lock.json yarn.lock + +# Vanilla build files +vanilla.js \ No newline at end of file diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index f89c2b6..af8ca5c 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -7,9 +7,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2 + with: + version: 8 - uses: actions/setup-node@v3 with: node-version: 21 + cache: 'pnpm' - name: Install dependendencies run: npm i diff --git a/.github/workflows/deploy-demo.yml b/.github/workflows/deploy-demo.yml index 8f28a28..2c78c74 100644 --- a/.github/workflows/deploy-demo.yml +++ b/.github/workflows/deploy-demo.yml @@ -10,9 +10,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2 + with: + version: 8 - uses: actions/setup-node@v3 with: node-version: 21 + cache: 'pnpm' - name: Install dependendencies run: npm i diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 456cdc3..bfd637c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,9 +13,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2 + with: + version: 8 - uses: actions/setup-node@v3 with: node-version: 21 + cache: 'pnpm' - name: Install dependendencies run: npm i @@ -44,9 +48,13 @@ jobs: steps: - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2 + with: + version: 8 - uses: actions/setup-node@v3 with: node-version: 21 + cache: 'pnpm' - name: Install dependendencies run: npm i diff --git a/.prettierignore b/.prettierignore index 812f04d..19be9eb 100644 --- a/.prettierignore +++ b/.prettierignore @@ -12,3 +12,6 @@ dist pnpm-lock.yaml package-lock.json yarn.lock + +# Vanilla build files +vanilla.js diff --git a/package.json b/package.json index 46f217a..2c2aafa 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,12 @@ "core": "cd packages/core && npm run dev", "demo": "cd demo && npm run dev", "lint": "prettier --check . && eslint .", + "lint:fix": "prettier --write . && eslint --fix .", "format": "prettier --write .", "check": "npm run check --workspaces --if-present", "test": "npm run test --workspaces --if-present", "build": "npm run build --workspaces --if-present", - "prepare": "npx husky install", + "prepare": "husky install", "publish-demo": "npm run build && cd demo && npm run gh-pages", "commit": "cz", "semantic-release": "semantic-release", diff --git a/packages/core/.gitignore b/packages/core/.gitignore index 229b2e3..e99f170 100644 --- a/packages/core/.gitignore +++ b/packages/core/.gitignore @@ -10,4 +10,6 @@ node_modules vite.config.js.timestamp-* vite.config.ts.timestamp-* .vscode -.idea \ No newline at end of file +.idea +vanilla.* +/**/*.tgz \ No newline at end of file diff --git a/packages/core/package.json b/packages/core/package.json index a1b46eb..e2e33ba 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -13,8 +13,11 @@ "build": "vite build && npm run package", "watch": "svelte-package --watch", "preview": "vite preview", - "package": "svelte-kit sync && svelte-package && publint", + "svelte:package": "npm run prepare && svelte-package", + "vanilla:package": "rollup -c ./rollup.config.vanilla.js", + "package": "run-s *:package && publint", "prepublishOnly": "npm run package", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "test": "vitest run", @@ -27,10 +30,30 @@ }, "./*.css": { "import": "./dist/styles/*.css" + }, + "./dist/styles/styles.css": { + "import": "./dist/styles/styles.css", + "default": "./dist/styles/styles.css" + }, + "./dist/styles/light.css": { + "import": "./dist/styles/light.css", + "default": "./dist/styles/light.css" + }, + "./dist/styles/dark.css": { + "import": "./dist/styles/dark.css", + "default": "./dist/styles/dark.css" + }, + "./vanilla": { + "types": "./vanilla.d.ts", + "import": "./vanilla.js" } }, + "svelte": "./dist/index.js", + "types": "./dist/index.d.ts", "main": "./dist/index.js", "files": [ + "vanilla.js", + "vanilla.d.ts", "dist", "!dist/**/*.test.*", "!dist/**/*.spec.*" @@ -40,20 +63,30 @@ }, "devDependencies": { "@sveltejs/kit": "^2.5.0", + "@babel/preset-env": "^7.23.9", + "@rollup/plugin-alias": "^5.1.0", + "@rollup/plugin-babel": "^6.0.4", + "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^11.1.6", "@sveltejs/package": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.2", "@types/diff": "^5.0.3", "dedent": "^1.5.1", + "esm-env": "^1.0.0", + "npm-run-all": "^4.1.5", "publint": "^0.1.9", + "rollup": "^4.9.6", + "rollup-plugin-copy": "^3.5.0", + "rollup-plugin-svelte": "^7.1.6", "svelte": "^4.0.5", "svelte-check": "^3.4.3", + "svelte-preprocess": "^5.1.3", "tslib": "^2.4.1", "typescript": "^5.0.0", "vite": "^5.1.3", "vitest": "^0.34.5" }, - "svelte": "./dist/index.js", - "types": "./dist/index.d.ts", "type": "module", "dependencies": { "diff": "^5.1.0", @@ -67,5 +100,8 @@ "merge", "mismerge", "diff" - ] + ], + "publishConfig": { + "access": "public" + } } diff --git a/packages/core/rollup.config.vanilla.js b/packages/core/rollup.config.vanilla.js new file mode 100644 index 0000000..7bce779 --- /dev/null +++ b/packages/core/rollup.config.vanilla.js @@ -0,0 +1,81 @@ +/// +/// Rollup configuration for the vanilla build which can be reused for +/// projects that don't use a framework like Svelte (i.e. Vue, React), or can be imported without the need of a bundler. +/// +import resolve from '@rollup/plugin-node-resolve'; +import typescript from '@rollup/plugin-typescript'; +import { getBabelOutputPlugin } from '@rollup/plugin-babel'; +import path from 'path'; +import svelte from 'rollup-plugin-svelte'; +import terser from '@rollup/plugin-terser'; +import sveltePreprocess from 'svelte-preprocess'; +import alias from '@rollup/plugin-alias'; +import copy from 'rollup-plugin-copy'; +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const coreSourcePath = __dirname; +const coreLibPath = path.join(coreSourcePath, 'src/lib'); + +const isProduction = !process.env.ROLLUP_WATCH; + +if (!isProduction) { + throw new Error('This build is only for production'); +} + +const outputFolder = path.join(__dirname); + +export default [ + { + input: path.join(coreLibPath, 'index.ts'), + output: [ + { + file: path.join(outputFolder, '/vanilla.js'), + format: 'es', + sourcemap: true, + inlineDynamicImports: true + } + ], + plugins: [ + alias({ + entries: [ + { + find: '$lib', + replacement: coreLibPath + } + ] + }), + svelte({ + preprocess: sveltePreprocess(), + compilerOptions: { + customElement: true + } + }), + resolve({ + browser: true, + exportConditions: ['svelte'] + }), + typescript({ + sourceMap: true, + inlineSources: true, + tsconfig: path.join(coreSourcePath, 'tsconfig.json'), + include: [path.join(coreLibPath, '**/*')], + declaration: false + }), + getBabelOutputPlugin({ + presets: ['@babel/preset-env'] + }), + copy({ + targets: [ + { + src: path.join(coreSourcePath, '/dist/index.d.ts'), + dest: outputFolder, + rename: 'vanilla.d.ts' + } + ] + }), + terser() + ] + } +]; diff --git a/packages/core/src/lib/components/MisMerge2.svelte b/packages/core/src/lib/components/MisMerge2.svelte index c53870b..5e2800d 100644 --- a/packages/core/src/lib/components/MisMerge2.svelte +++ b/packages/core/src/lib/components/MisMerge2.svelte @@ -1,3 +1,10 @@ + +