Skip to content

Commit

Permalink
fix(build): allow interop from cjs project
Browse files Browse the repository at this point in the history
Needed for the publicodes-language-server to work.

NOTE: tested with nosgestesclimat, but maybe it's breaking other projects?
  • Loading branch information
EmileRolley committed Apr 23, 2024
1 parent f219835 commit 04a18d8
Show file tree
Hide file tree
Showing 17 changed files with 312 additions and 288 deletions.
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.0.7",
"description": "A set of utility functions to build tools around Publicodes models",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsup",
"watch": "tsup --watch",
Expand Down Expand Up @@ -59,28 +62,27 @@
"jest": "^29.4.1",
"prettier": "^3.0.0",
"ts-jest": "^29.0.4",
"ts-node": "^10.9.2",
"tsup": "^6.5.0",
"tsup": "^8.0.2",
"typedoc": "^0.24.8",
"typedoc-plugin-export-functions": "^1.0.0",
"typescript": "^4.9.4",
"yaml": "^2.3.1"
},
"tsup": {
"verbose": true,
"entry": [
"source/index.ts",
"source/optims/index.ts",
"source/compilation/index.ts"
"src/index.ts",
"src/optims/index.ts",
"src/compilation/index.ts"
],
"cjsInterop": true,
"format": [
"cjs",
"esm"
],
"allowJs": true,
"sourceMap": true,
"dts": true,
"clean": true,
"target": "es2020",
"skipNodeModulesBundle": true
},
"publishConfig": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import glob from 'glob'
import yaml from 'yaml'
import { readFileSync, statSync } from 'fs'
import fs from 'fs'
import { getDoubleDefError, RawRules } from '../commons'
import { resolveImports } from './resolveImports'

Expand Down Expand Up @@ -41,15 +41,15 @@ export function getModelFromSource(
opts?: GetModelFromSourceOptions,
): RawRules {
try {
if (statSync(sourcePath).isDirectory()) {
if (fs.statSync(sourcePath).isDirectory()) {
sourcePath = sourcePath + '/**/*.publicodes'
}
} catch (e) {}
const { jsonModel, namespaces } = glob
.sync(sourcePath, { ignore: opts?.ignore })
.reduce(
({ jsonModel, namespaces }, filePath: string) => {
const rules: RawRules = yaml.parse(readFileSync(filePath, 'utf-8'))
const rules: RawRules = yaml.parse(fs.readFileSync(filePath, 'utf-8'))
if (rules == null) {
console.warn(`⚠️ ${filePath} is empty, skipping...`)
return jsonModel
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RawRule, RuleName } from './commons'
type SerializedRule = RawRule | number | string | null

function serializedRuleToRawRule(serializedRule: SerializedRule): RawRule {
if (typeof serializedRule === 'object') {
if (serializedRule !== null && typeof serializedRule === 'object') {
return serializedRule
}
return {
Expand Down
2 changes: 1 addition & 1 deletion test/compilation/getModelFromSource.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getModelFromSource } from '../../source/compilation/getModelFromSource'
import { getModelFromSource } from '../../src/compilation/getModelFromSource'
import { join, resolve } from 'path'

const testDataDir = resolve('./test/compilation/data/')
Expand Down
6 changes: 3 additions & 3 deletions test/optims/constantFolding.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Engine, { RuleNode } from 'publicodes'
import { serializeParsedRules } from '../../source'
import { RuleName, RawRules, disabledLogger } from '../../source/commons'
import { constantFolding } from '../../source/optims/'
import { serializeParsedRules } from '../../src'
import { RuleName, RawRules, disabledLogger } from '../../src/commons'
import { constantFolding } from '../../src/optims/'
import { callWithEngine } from '../utils.test'

function constantFoldingWith(rawRules: any, targets?: RuleName[]): RawRules {
Expand Down
5 changes: 1 addition & 4 deletions test/parseExpression.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
serializeParsedExprAST,
substituteInParsedExpr,
} from '../source/commons'
import { serializeParsedExprAST, substituteInParsedExpr } from '../src/commons'

describe('substituteInParsedExpr', () => {
it('should return the same parsed expression if no occurence of the variable is found', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/serializeParsedRules.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Engine from 'publicodes'
import { serializeParsedRules } from '../source/index'
import { serializeParsedRules } from '../src/index'

describe('API > mecanisms list', () => {
it('should serialize empty rules', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RuleName, disabledLogger } from '../source/commons'
import { RuleName, disabledLogger } from '../src/commons'
import Engine from 'publicodes'
import type { ParsedRules } from 'publicodes'

Expand Down
33 changes: 19 additions & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
{
"compilerOptions": {
"target": "esnext",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"rootDir": "src",
"outDir": "dist",
"rootDir": "source",
"types": ["node", "jest"],
"esModuleInterop": true,
"allowJs": true,
"lib": ["es2021"],
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"sourceMap": true,
"types": [
"jest",
"node"
],
"declaration": true,
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true
},
"ts-node": {
"transpileOnly": true,
"files": true,
},
"include": ["source/**/*.ts"],
"exclude": ["./node_modules/", "./dist/", "./jest.config.js", "./test/"],
"include": [
"src"
],
"exclude": [
"./node_modules/",
"./dist/",
"./jest.config.js",
"./test/"
]
}
2 changes: 1 addition & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://typedoc.org/schema.json",
"name": "@publicodes/tools API",
"entryPoints": ["./source", "./source/optims/", "./source/compilation/"],
"entryPoints": ["./src", "./src/optims/", "./src/compilation/"],
"navigationLinks": {
"GitHub": "https://github.com/publicodes/tools"
},
Expand Down
Loading

0 comments on commit 04a18d8

Please sign in to comment.