Skip to content

Commit

Permalink
Merge pull request #14 from tonysamperi/v5-webpack
Browse files Browse the repository at this point in the history
V5 webpack
  • Loading branch information
tonysamperi authored Jun 5, 2024
2 parents 312fd76 + fb541a6 commit fc54b13
Show file tree
Hide file tree
Showing 13 changed files with 754 additions and 208 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/npm-publish-github-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.3.0
node-version: 20.9.0
registry-url: https://registry.npmjs.org/
- run: npm i -g yarn
- run: yarn install --check-files
- run: npm run build
- run: npm publish
- run: |
pkgversion=$(node -p -e "require('./package.json').version")
if [[ $pkgversion == *"beta"* ]]; then
npm run publish:beta
else
npm publish
fi
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
57 changes: 57 additions & 0 deletions .idx/dev.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# To learn more about how to use Nix to configure your environment
# see: https://developers.google.com/idx/guides/customize-idx-env
{ pkgs, ... }: {
# Which nixpkgs channel to use.
channel = "stable-23.11"; # or "unstable"

# Use https://search.nixos.org/packages to find packages
packages = [
# pkgs.go
# pkgs.python311
# pkgs.python311Packages.pip
pkgs.nodejs_20
pkgs.nodePackages.yarn
];

# Sets environment variables in the workspace
env = { };
idx = {
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
extensions = [
# "vscodevim.vim"
];

# Enable previews
previews = {
enable = true;
previews = {
# web = {
# # Example: run "npm run dev" with PORT set to IDX's defined port for previews,
# # and show it in IDX's web preview panel
# command = ["npm" "run" "dev"];
# manager = "web";
# env = {
# # Environment variables to set for your server
# PORT = "$PORT";
# };
# };
};
};

# Workspace lifecycle hooks
workspace = {
# Runs when a workspace is first created
onCreate = {
# Example: install JS dependencies from NPM
# npm-install = "npm install";
};
# Runs when the workspace is (re)started
onStart = {
# Example: start a background task to watch and re-build backend code
# watch-backend = "npm run watch-backend";
};
};
};
}


40 changes: 24 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-luxon",
"version": "5.0.2",
"version": "5.0.3-beta.4",
"license": "MIT",
"description": "Typescript version of the \"Immutable date wrapper\"",
"author": "Tony Samperi",
Expand All @@ -9,16 +9,24 @@
"immutable",
"typescript"
],
"repository": "https://github.com/tonysamperi/ts-luxon",
"repository": {
"type": "git",
"url": "git+https://github.com/tonysamperi/ts-luxon.git"
},
"homepage": "https://tonysamperi.github.io/ts-luxon/",
"type": "commonjs",
"main": "./dist/ts-luxon.umd.js",
"types": "./dist/index.d.ts",
"module": "./dist/ts-luxon.es6.mjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/ts-luxon.es6.mjs",
"default": "./dist/ts-luxon.umd.js"
"require": {
"types": "./dist/index.d.ts",
"import": "./dist/ts-luxon.cjs.js"
},
"default": {
"types": "./dist/index.d.ts",
"default": "./dist/ts-luxon.umd.js"
}
}
},
"files": [
Expand All @@ -29,9 +37,11 @@
"node": ">=13"
},
"scripts": {
"prepublishOnly": "node ./test/test-dist.js",
"build:watch": "npm run build -- -w",
"build": "rimraf dist && rollup -c rollup.config.mjs",
"prepublishOnly": "node ./test/test-dist.mjs",
"build": "npm run clean && npm run build:umd && npm run build:cjs",
"build:cjs": "webpack --config ./webpack.cjs.config.js",
"build:umd": "webpack --config ./webpack.umd.config.js",
"clean": "rimraf dist",
"jest": "jest",
"test": "jest --coverage",
"lint": "tslint --project tsconfig.json",
Expand All @@ -42,12 +52,6 @@
"publish:beta": "npm publish --tag beta"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.8",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/benchmark": "^2.1.0",
"@types/jest": "^29.5.4",
"@typescript-eslint/eslint-plugin": "^6.4.1",
Expand All @@ -59,11 +63,15 @@
"jest": "^29.6.4",
"rimraf": "^5.0.7",
"rollup": "^4.18.0",
"string-replace-loader": "^3.1.0",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tslib": "^2.0.0",
"typedoc": "^0.23.21",
"typescript": "~5.0.4"
"typescript": "^5.4.5",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
},
"sideEffects": false
}
39 changes: 0 additions & 39 deletions rollup.config.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NormalizedDurationUnit } from "./types/duration";

export * from "./types/public";

const VERSION = "__BUILD_VRS__"; // REPLACED WITH ROLLUP
const VERSION = "__BUILD_VRS__"; // REPLACED WITH WEBPACK

export {
DateTime,
Expand Down
7 changes: 0 additions & 7 deletions test/test-dist.js

This file was deleted.

9 changes: 9 additions & 0 deletions test/test-dist.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as tsLuxon from "../dist/ts-luxon.umd.js";
import pkg from "../package.json" assert { type: "json" };

(() => {
if (pkg.version !== tsLuxon.VERSION) {
console.error(`Version mismatch! Expected ${pkg.version}, got ${tsLuxon.VERSION}. Rebuild the package to solve!`)
throw new Error(`PGK-LIB VERSION MISMATCH!`);
}
})();
14 changes: 14 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": [
"./tsconfig.json"
],
"compilerOptions": {
"module": "CommonJS",
"target": "esnext",
"moduleResolution": "node",
"lib": [
"esnext"
],
"outDir": "dist"
}
}
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"test"
],
"compilerOptions": {
"module": "es6",
"target": "es6",
"module": "CommonJS",
"target": "es5",
"lib": [
"es5"
"esnext"
],
"allowJs": true,
"importHelpers": true,
"declaration": true,
"sourceMap": true,
Expand Down
31 changes: 31 additions & 0 deletions webpack.cjs.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { resolve } = require("path");
const webpackCommon = require("./webpack.common");

webpackCommon.module.rules.push({
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
configFile: "tsconfig.cjs.json"
}
},
exclude: /node_modules/
});

module.exports = {
...webpackCommon,
entry: {
'ts-luxon.cjs': './src/index.ts'
},
experiments: {
outputModule: true,
},
output: {
path: resolve('dist'),
globalObject: "this",
filename: '[name].js',
library: {
type: "module"
}
}
};
35 changes: 35 additions & 0 deletions webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { version } = require("./package.json");

// from "(.*?)(?<!\.js)";

module.exports = {
mode: "development",
optimization: {
minimize: false
},
resolve: {
extensions: ['.ts', ".js"]
},
devtool: 'source-map',
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: [".ts", ".tsx", ".js"],
// Add support for TypeScripts fully qualified ESM imports.
extensionAlias: {
".js": [".js", ".ts"],
".mjs": [".mjs", ".mts"]
}
},
module: {
rules: [
{
test: /\.m?[jt]s$/,
loader: 'string-replace-loader',
options: {
search: "__BUILD_VRS__",
replace: version,
}
},
]
}
};
25 changes: 25 additions & 0 deletions webpack.umd.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { resolve } = require("path");
const webpackCommon = require("./webpack.common");

webpackCommon.module.rules.push({
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
});

module.exports = {
...webpackCommon,
entry: {
'ts-luxon.umd': './src/index.ts'
},
output: {
path: resolve('dist'),
globalObject: "this",
filename: '[name].js',
library: {
type: "umd",
name: "tsLuxon"
},
umdNamedDefine: true
}
};
Loading

0 comments on commit fc54b13

Please sign in to comment.