Skip to content

Commit

Permalink
fix(build): fix typescript error when importing delivery options
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Apr 11, 2024
1 parent 798a3aa commit bf8af9f
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 41 deletions.
11 changes: 8 additions & 3 deletions apps/delivery-options/private/getSharedConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {fileURLToPath} from 'node:url';
import {type UserConfig, type ConfigEnv} from 'vite';
import {resolveAlias} from '@myparcel-do/build-vite';

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const getSharedConfig = ({mode}: ConfigEnv) => {
Expand All @@ -12,9 +13,13 @@ export const getSharedConfig = ({mode}: ConfigEnv) => {
},

resolve: {
alias: {
pinia: fileURLToPath(new URL('../../../node_modules/pinia/dist/pinia.prod.cjs', import.meta.url)),
},
alias: [
...resolveAlias,
{
find: 'pinia',
replacement: fileURLToPath(new URL('../../../node_modules/pinia/dist/pinia.prod.cjs', import.meta.url)),
},
],
},
} satisfies Partial<UserConfig>;
};
5 changes: 2 additions & 3 deletions apps/sandbox/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {defineConfig} from 'vitest/config';
import customTsConfig from 'vite-plugin-custom-tsconfig';
import vue from '@vitejs/plugin-vue';
import {resolveAlias} from '@myparcel-do/build-vite';

export const PORT = 9860;

Expand Down Expand Up @@ -32,9 +33,7 @@ export default defineConfig(({mode}) => {
},

resolve: {
alias: {
'@myparcel/delivery-options': `${dirname}/../delivery-options/src`,
},
alias: resolveAlias,
},

define: {
Expand Down
4 changes: 3 additions & 1 deletion libs/build-vite/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {type ConfigEnv, type UserConfigFn} from 'vitest/config';
import {type UserConfig} from 'vite';
import {type UserConfig, type Alias} from 'vite';
import {type PromiseOr, type RecursivePartial} from '@myparcel/ts-utils';

declare function createViteConfig<>(
config?: RecursivePartial<UserConfig> | ((env: ConfigEnv) => PromiseOr<RecursivePartial<UserConfig>>),
): UserConfigFn;

declare const resolveAlias: Alias[];
24 changes: 23 additions & 1 deletion libs/build-vite/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
import path from 'node:path';
import customTsConfig from 'vite-plugin-custom-tsconfig';
import {mergeConfig} from 'vite';
import vue from '@vitejs/plugin-vue';

const dirname = path.dirname(new URL(import.meta.url).pathname);

/** @type {import('vitest/config').Alias[]} */
export const resolveAlias = [
{
find: '@myparcel/delivery-options',
replacement: path.resolve(dirname, '../../apps/delivery-options/src'),
},
{
find: '@myparcel-do/shared/testing',
replacement: path.resolve(dirname, '../../libs/shared/src/__tests__'),
},
{
find: /^@myparcel-do\/(.+)/,
replacement: path.resolve(dirname, '../../libs/$1/src'),
},
];

/** @type {import('vitest/config').UserConfigFn} */
const createCommonViteConfig = (env) => {
const isProd = env.mode === 'production';

return {
plugins: [vue(), customTsConfig({tsConfigPath: 'tsconfig.base.json'})],

Expand All @@ -14,6 +32,10 @@ const createCommonViteConfig = (env) => {
sourcemap: !isProd,
},

resolve: {
alias: resolveAlias,
},

test: {
coverage: {
all: true,
Expand Down
19 changes: 5 additions & 14 deletions libs/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,24 @@
"sideEffects": false,
"type": "module",
"exports": {
".": {
"import": "./src/index.ts",
"require": "./src/index.ts"
},
"./testing": {
"import": "./src/__tests__/index.ts",
"require": "./src/__tests__/index.ts"
}
".": "./dist/index.js",
"./testing": "./dist/testing.js"
},
"main": "./src/index.ts",
"module": "./src/index.ts",
"types": "./dist/index.d.ts",
"files": [
"./src",
"./dist"
],
"scripts": {
"build": "run ws:vue:build \"$(pwd)\"",
"build:dev": "run ws:vue:build \"$(pwd)\"",
"build": "vite build",
"build:dev": "vite build --mode development",
"clean": "run ws:clean \"$(pwd)\"",
"lint": "run ws:lint \"$(pwd)\"",
"lint:fix": "run ws:lint:fix \"$(pwd)\"",
"test": "run ws:test \"$(pwd)\"",
"test:coverage": "run ws:test:coverage \"$(pwd)\"",
"test:run": "run ws:test:run \"$(pwd)\"",
"test:update": "run ws:test:update \"$(pwd)\"",
"typecheck": "run ws:vue:typecheck \"$(pwd)\""
"typecheck": "vue-tsc --project tsconfig.base.json --noEmit"
},
"dependencies": {
"@myparcel-do/shared": "workspace:*",
Expand Down
15 changes: 9 additions & 6 deletions libs/shared/src/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@ import {DeliveryTypeName, PackageTypeName, PlatformName, ShipmentOptionName} fro
import {type DropOffEntryObject} from '../types';
import {CarrierSetting} from './enums';

export const SUPPORTED_PLATFORMS = [PlatformName.MyParcel, PlatformName.SendMyParcel] as const;
export const SUPPORTED_PLATFORMS = Object.freeze([PlatformName.MyParcel, PlatformName.SendMyParcel]);

export const SUPPORTED_DELIVERY_TYPES = [
export const SUPPORTED_DELIVERY_TYPES = Object.freeze([
DeliveryTypeName.Standard,
DeliveryTypeName.Evening,
DeliveryTypeName.Morning,
DeliveryTypeName.Pickup,
] as const;
]);

export const SUPPORTED_SHIPMENT_OPTIONS = [ShipmentOptionName.OnlyRecipient, ShipmentOptionName.Signature] as const;
export const SUPPORTED_SHIPMENT_OPTIONS = Object.freeze([
ShipmentOptionName.OnlyRecipient,
ShipmentOptionName.Signature,
]);

export const SUPPORTED_PACKAGE_TYPES = [
export const SUPPORTED_PACKAGE_TYPES = Object.freeze([
PackageTypeName.Package,
PackageTypeName.Mailbox,
PackageTypeName.DigitalStamp,
PackageTypeName.PackageSmall,
] as const;
]);

export const DEFAULT_PLATFORM = PlatformName.MyParcel;

Expand Down
28 changes: 28 additions & 0 deletions libs/shared/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import dts from 'vite-plugin-dts';
import {isCI} from 'ci-info';
import {createViteConfig} from '@myparcel-do/build-vite';

const dirname = new URL('.', import.meta.url).pathname;

export default createViteConfig((env) => {
const isProd = env.mode === 'production';

return {
plugins: [dts({entryRoot: 'src'})],

build: {
sourcemap: !isCI && isProd,
lib: {
entry: {
index: `${dirname}/src/index.ts`,
testing: `${dirname}/src/__tests__/index.ts`,
},
formats: ['es'],
},
},

test: {
setupFiles: [`${dirname}/src/__tests__/vitest-setup.ts`],
},
};
});
8 changes: 0 additions & 8 deletions libs/shared/vitest.config.ts

This file was deleted.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@
"ws:test": "cd $0 && vitest --passWithNoTests",
"ws:test:coverage": "cd $0 && vitest run --coverage --passWithNoTests",
"ws:test:run": "cd $0 && vitest run --passWithNoTests",
"ws:test:update": "cd $0 && vitest run -u --passWithNoTests",
"ws:ts:build": "cd $0 && tsc --project tsconfig.base.json --declaration --emitDeclarationOnly --noEmit false --declarationDir dist",
"ws:ts:typecheck": "cd $0 && tsc --project tsconfig.base.json --noEmit",
"ws:vue:build": "cd $0 && vue-tsc --project tsconfig.base.json --declaration --emitDeclarationOnly --noEmit false --declarationDir dist",
"ws:vue:typecheck": "cd $0 && vue-tsc --project tsconfig.base.json --noEmit"
"ws:test:update": "cd $0 && vitest run -u --passWithNoTests"
},
"lint-staged": {
"*.{json,md,yml}": "prettier --write",
Expand Down
5 changes: 5 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"extends": "@vue/tsconfig/tsconfig.dom.json",
"compilerOptions": {
"noEmitOnError": false,
"paths": {
"@myparcel/delivery-options": ["./apps/delivery-options/src"],
"@myparcel-do/shared/testing": ["./libs/shared/src/__tests__"],
"@myparcel-do/*": ["./libs/*/src"]
},
"types": ["node", "vite/client"]
},
"include": [],
Expand Down

0 comments on commit bf8af9f

Please sign in to comment.