From b8cf73471bfa91ddeb3c5f0886c00f0e8edecd0a Mon Sep 17 00:00:00 2001 From: MohammadHasan Akbari Date: Sun, 28 Jan 2024 23:05:39 +0330 Subject: [PATCH 1/4] refactor: remove extra codes --- spec/ajv.ts | 1 - spec/ajv2019.ts | 1 - spec/ajv2020.ts | 1 - spec/ajv_jtd.ts | 1 - 4 files changed, 4 deletions(-) diff --git a/spec/ajv.ts b/spec/ajv.ts index bccfd8798..67123ebd5 100644 --- a/spec/ajv.ts +++ b/spec/ajv.ts @@ -3,4 +3,3 @@ const AjvClass: typeof Ajv = typeof window == "object" ? (window as any).ajv7 : export default AjvClass module.exports = AjvClass -module.exports.default = AjvClass diff --git a/spec/ajv2019.ts b/spec/ajv2019.ts index e7ccb8d76..142c907e6 100644 --- a/spec/ajv2019.ts +++ b/spec/ajv2019.ts @@ -4,4 +4,3 @@ const AjvClass: typeof Ajv2019 = export default AjvClass module.exports = AjvClass -module.exports.default = AjvClass diff --git a/spec/ajv2020.ts b/spec/ajv2020.ts index e231c4345..19624f5cd 100644 --- a/spec/ajv2020.ts +++ b/spec/ajv2020.ts @@ -4,4 +4,3 @@ const AjvClass: typeof Ajv2020 = export default AjvClass module.exports = AjvClass -module.exports.default = AjvClass diff --git a/spec/ajv_jtd.ts b/spec/ajv_jtd.ts index 9a810f72b..5ebee1be1 100644 --- a/spec/ajv_jtd.ts +++ b/spec/ajv_jtd.ts @@ -4,4 +4,3 @@ const AjvClass: typeof AjvJTD = export default AjvClass module.exports = AjvClass -module.exports.default = AjvClass From 25075099e410835e1f23e1fcced019287d6928cc Mon Sep 17 00:00:00 2001 From: MohammadHasan Akbari Date: Mon, 29 Jan 2024 06:01:20 +0330 Subject: [PATCH 2/4] refactor: add Ajv dedfault --- lib/standalone/index.ts | 2 +- spec/ajv.ts | 1 + spec/ajv2019.ts | 1 + spec/ajv2020.ts | 1 + spec/ajv_jtd.ts | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/standalone/index.ts b/lib/standalone/index.ts index b6129ce9e..786a4afd5 100644 --- a/lib/standalone/index.ts +++ b/lib/standalone/index.ts @@ -34,7 +34,7 @@ function standaloneCode( // Always do named export as `validate` rather than the variable `n` which is `validateXX` for known export value return `"use strict";${_n}export const validate = ${n};${_n}export default ${n};${_n}${vCode}` } - return `"use strict";${_n}module.exports = ${n};${_n}module.exports.default = ${n};${_n}${vCode}` + return `"use strict";${_n}module.exports = ${n};${_n}module.exports.Ajv = ${n};${_n}${vCode}` } function multiExportsCode( diff --git a/spec/ajv.ts b/spec/ajv.ts index 67123ebd5..6628bbd36 100644 --- a/spec/ajv.ts +++ b/spec/ajv.ts @@ -3,3 +3,4 @@ const AjvClass: typeof Ajv = typeof window == "object" ? (window as any).ajv7 : export default AjvClass module.exports = AjvClass +module.exports.Ajv = AjvClass diff --git a/spec/ajv2019.ts b/spec/ajv2019.ts index 142c907e6..1025fb9d3 100644 --- a/spec/ajv2019.ts +++ b/spec/ajv2019.ts @@ -4,3 +4,4 @@ const AjvClass: typeof Ajv2019 = export default AjvClass module.exports = AjvClass +module.exports.Ajv = AjvClass diff --git a/spec/ajv2020.ts b/spec/ajv2020.ts index 19624f5cd..1e7f93c14 100644 --- a/spec/ajv2020.ts +++ b/spec/ajv2020.ts @@ -4,3 +4,4 @@ const AjvClass: typeof Ajv2020 = export default AjvClass module.exports = AjvClass +module.exports.Ajv = AjvClass diff --git a/spec/ajv_jtd.ts b/spec/ajv_jtd.ts index 5ebee1be1..9245054a3 100644 --- a/spec/ajv_jtd.ts +++ b/spec/ajv_jtd.ts @@ -4,3 +4,4 @@ const AjvClass: typeof AjvJTD = export default AjvClass module.exports = AjvClass +module.exports.Ajv = AjvClass From 85f1b46b0aab0fafe246499f00c772678d9e9d6b Mon Sep 17 00:00:00 2001 From: MohammadHasan Akbari Date: Mon, 29 Jan 2024 06:24:15 +0330 Subject: [PATCH 3/4] refactor: change CJS test code --- spec/standalone.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/standalone.spec.ts b/spec/standalone.spec.ts index 45e3dad18..b123515c8 100644 --- a/spec/standalone.spec.ts +++ b/spec/standalone.spec.ts @@ -291,7 +291,7 @@ describe("standalone code generation", () => { testExportTypeCjs(moduleCode, true) const m = requireFromString(moduleCode) testExport(m) - testExport(m.default) + testExport(m.Ajv) function testExport(validate: AnyValidateFunction) { assert.strictEqual(validate(1), true) From fdf7e70dc3ad389dd6e27f653a10674adb33f3b8 Mon Sep 17 00:00:00 2001 From: MohammadHasan Akbari Date: Sat, 13 Jul 2024 04:49:25 +0330 Subject: [PATCH 4/4] chore: backward compatibility --- lib/standalone/index.ts | 2 +- spec/ajv.ts | 1 + spec/ajv2019.ts | 1 + spec/ajv2020.ts | 1 + spec/ajv_jtd.ts | 1 + spec/standalone.spec.ts | 1 + 6 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/standalone/index.ts b/lib/standalone/index.ts index 786a4afd5..47a2a3bb4 100644 --- a/lib/standalone/index.ts +++ b/lib/standalone/index.ts @@ -34,7 +34,7 @@ function standaloneCode( // Always do named export as `validate` rather than the variable `n` which is `validateXX` for known export value return `"use strict";${_n}export const validate = ${n};${_n}export default ${n};${_n}${vCode}` } - return `"use strict";${_n}module.exports = ${n};${_n}module.exports.Ajv = ${n};${_n}${vCode}` + return `"use strict";${_n}module.exports = ${n};${_n}module.exports.default = ${n};${_n}module.exports.Ajv = ${n};${_n}${vCode}` } function multiExportsCode( diff --git a/spec/ajv.ts b/spec/ajv.ts index 6628bbd36..8a1a58696 100644 --- a/spec/ajv.ts +++ b/spec/ajv.ts @@ -4,3 +4,4 @@ const AjvClass: typeof Ajv = typeof window == "object" ? (window as any).ajv7 : export default AjvClass module.exports = AjvClass module.exports.Ajv = AjvClass +module.exports.default = AjvClass diff --git a/spec/ajv2019.ts b/spec/ajv2019.ts index 1025fb9d3..5498edd03 100644 --- a/spec/ajv2019.ts +++ b/spec/ajv2019.ts @@ -5,3 +5,4 @@ const AjvClass: typeof Ajv2019 = export default AjvClass module.exports = AjvClass module.exports.Ajv = AjvClass +module.exports.default = AjvClass diff --git a/spec/ajv2020.ts b/spec/ajv2020.ts index 1e7f93c14..9d6da3075 100644 --- a/spec/ajv2020.ts +++ b/spec/ajv2020.ts @@ -5,3 +5,4 @@ const AjvClass: typeof Ajv2020 = export default AjvClass module.exports = AjvClass module.exports.Ajv = AjvClass +module.exports.default = AjvClass diff --git a/spec/ajv_jtd.ts b/spec/ajv_jtd.ts index 9245054a3..6b5a95c43 100644 --- a/spec/ajv_jtd.ts +++ b/spec/ajv_jtd.ts @@ -5,3 +5,4 @@ const AjvClass: typeof AjvJTD = export default AjvClass module.exports = AjvClass module.exports.Ajv = AjvClass +module.exports.default = AjvClass diff --git a/spec/standalone.spec.ts b/spec/standalone.spec.ts index b123515c8..57fc6aa8c 100644 --- a/spec/standalone.spec.ts +++ b/spec/standalone.spec.ts @@ -292,6 +292,7 @@ describe("standalone code generation", () => { const m = requireFromString(moduleCode) testExport(m) testExport(m.Ajv) + testExport(m.default) function testExport(validate: AnyValidateFunction) { assert.strictEqual(validate(1), true)