Skip to content

Commit

Permalink
Resolve 4 no-var-requires problems
Browse files Browse the repository at this point in the history
  • Loading branch information
dansteren committed Dec 1, 2023
1 parent 334402e commit 7f499e4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const temporarilyDisabledRules = {
'@typescript-eslint/ban-ts-comment': 'off', // 39 problems
'@typescript-eslint/no-explicit-any': 'off', // 321 problems
'@typescript-eslint/no-unused-vars': 'off', // 33 problems
'@typescript-eslint/no-var-requires': 'off', // 12 problems
'@typescript-eslint/no-var-requires': 'off', // 8 problems
'@typescript-eslint/prefer-as-const': 'off', // 45 problems
'no-constant-condition': 'off', // 1 problem
'no-undef': 'off', // 11 problems
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"devDependencies": {
"@dfinity/agent": "^0.19.2",
"@types/fs-extra": "9.0.13",
"@types/text-encoding": "^0.0.39",
"@typescript-eslint/eslint-plugin": "^6.13.0",
"@typescript-eslint/parser": "^6.13.0",
"eslint": "^8.54.0",
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/generate_candid_and_canister_methods.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createContext, Script } from 'vm';

import { toDidString } from '../lib/candid/did_file';
import {
DidVisitor,
Expand All @@ -9,8 +11,6 @@ export function generateCandidAndCanisterMethods(mainJs: string): {
candid: string;
canisterMethods: CanisterMethods;
} {
const vm = require('vm');

const sandbox = {
globalThis: {},
crypto: {
Expand All @@ -29,9 +29,9 @@ export function generateCandidAndCanisterMethods(mainJs: string): {
TextDecoder,
TextEncoder
};
const context = new vm.createContext(sandbox);
const context = createContext(sandbox);

const script = new vm.Script(mainJs);
const script = new Script(mainJs);
script.runInContext(context);

const canisterMethods = (sandbox.exports as any).canisterMethods;
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/utils/global_paths.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { homedir } from 'os';
import { join, resolve } from 'path';

import { rust_version, version as azleVersion } from '../../../package.json';

export const GLOBAL_AZLE_CONFIG_DIR = resolve(
require('os').homedir(),
homedir(),
join('.config', 'azle')
);
export const GLOBAL_AZLE_RUST_DIR = join(
Expand Down
5 changes: 3 additions & 2 deletions src/lib/globals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Buffer } from 'buffer';
import { TextDecoder, TextEncoder } from 'text-encoding';

import { ic } from './ic';
import { AzleIc } from './ic/types/azle_ic';
Expand All @@ -12,8 +13,8 @@ declare global {
var _azleGuardFunctions: { [key: string]: () => any };
}

globalThis.TextDecoder = require('text-encoding').TextDecoder;
globalThis.TextEncoder = require('text-encoding').TextEncoder;
globalThis.TextDecoder = TextDecoder;
globalThis.TextEncoder = TextEncoder;
globalThis._azleIcTimers = {};
globalThis._azleResolveIds = {};
globalThis._azleRejectIds = {};
Expand Down

0 comments on commit 7f499e4

Please sign in to comment.