Skip to content

Commit c0b1d9a

Browse files
committed
Fix tsgo destructuring bug in all lib files
Replace destructuring from global objects with direct property access to work around tsgo transpilation bug that causes runtime errors. References: SocketDev/socket-packageurl-js#3
1 parent 117212a commit c0b1d9a

20 files changed

+150
-39
lines changed

registry/src/lib/constants/ENV.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { envAsBoolean, envAsString } from '../env.js'
22
import WIN32 from './WIN32'
33

4-
const { freeze: ObjectFreeze, hasOwn: ObjectHasOwn } = Object
4+
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
5+
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
6+
// `exports.SomeName = void 0;` which causes runtime errors.
7+
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
8+
const ObjectFreeze = Object.freeze
9+
const ObjectHasOwn = Object.hasOwn
510
const { env } = process
611

712
const DEBUG = envAsString(env['DEBUG'])

registry/src/lib/constants/NODE_HARDEN_FLAGS.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import WIN32 from './WIN32'
22

3-
const { freeze: ObjectFreeze } = Object
3+
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
4+
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
5+
// `exports.SomeName = void 0;` which causes runtime errors.
6+
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
7+
const ObjectFreeze = Object.freeze
48

59
export default ObjectFreeze(
610
// Harden Node security.

registry/src/lib/constants/NODE_NO_WARNINGS_FLAGS.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import SUPPORTS_NODE_DISABLE_WARNING_FLAG from './SUPPORTS_NODE_DISABLE_WARNING_FLAG'
22

3-
const { freeze: ObjectFreeze } = Object
3+
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
4+
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
5+
// `exports.SomeName = void 0;` which causes runtime errors.
6+
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
7+
const ObjectFreeze = Object.freeze
48

59
export default ObjectFreeze(
610
SUPPORTS_NODE_DISABLE_WARNING_FLAG

registry/src/lib/constants/ipc-promise.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import handler from './ipc-handler'
33
import ipcObject from './ipc-object'
44
import target from './ipc-target'
55

6-
const { assign: ObjectAssign, freeze: ObjectFreeze } = Object
6+
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
7+
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
8+
// `exports.SomeName = void 0;` which causes runtime errors.
9+
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
10+
const ObjectAssign = Object.assign
11+
const ObjectFreeze = Object.freeze
712

813
export default new Promise(
914
// The Promise executor is immediately executed.

registry/src/lib/constants/maintained-node-versions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import browsersList from '../../external/browserslist'
22
import semver from '../../external/semver'
33

4-
const { freeze: ObjectFreeze } = Object
4+
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
5+
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
6+
// `exports.SomeName = void 0;` which causes runtime errors.
7+
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
8+
const ObjectFreeze = Object.freeze
59

610
// Under the hood browserlist uses the node-releases package which is out of date:
711
// https://github.com/chicoxyzzy/node-releases/issues/37

registry/src/lib/constants/node-debug-flags.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import ENV from './ENV'
22

3-
const { freeze: ObjectFreeze } = Object
3+
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
4+
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
5+
// `exports.SomeName = void 0;` which causes runtime errors.
6+
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
7+
const ObjectFreeze = Object.freeze
48

59
export default ObjectFreeze(
610
ENV.SOCKET_CLI_DEBUG ? ['--trace-uncaught', '--trace-warnings'] : [],

registry/src/lib/constants/package-extensions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const { freeze: ObjectFreeze } = Object
1+
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
2+
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
3+
// `exports.SomeName = void 0;` which causes runtime errors.
4+
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
5+
const ObjectFreeze = Object.freeze
26

37
const yarnPkgExtensions: { packageExtensions: any[] } =
48
/*@__PURE__*/ require('../../external/@yarnpkg/extensions')

registry/src/lib/constants/package-manager-cache-names.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const { freeze: ObjectFreeze } = Object
1+
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
2+
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
3+
// `exports.SomeName = void 0;` which causes runtime errors.
4+
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
5+
const ObjectFreeze = Object.freeze
26

37
// Package manager cache directory names.
48
// These are the standard directory names used by each package manager

registry/src/lib/debug.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* Provides Socket CLI specific debug functionality and logging formatters.
44
*/
55

6-
const { apply: ReflectApply } = Reflect
6+
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
7+
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
8+
// `exports.SomeName = void 0;` which causes runtime errors.
9+
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
10+
const ReflectApply = Reflect.apply
711

812
const { hasOwn } = /*@__PURE__*/ require('./objects')
913
const { applyLinePrefix } = /*@__PURE__*/ require('./strings')

registry/src/lib/env.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
*/
55

66
const NumberCtor = Number
7-
const { isFinite: NumberIsFinite, parseInt: NumberParseInt } = NumberCtor
7+
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
8+
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
9+
// `exports.SomeName = void 0;` which causes runtime errors.
10+
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
11+
const NumberIsFinite = Number.isFinite
12+
const NumberParseInt = Number.parseInt
813
const StringCtor = String
914

1015
/**

0 commit comments

Comments
 (0)