Skip to content

Commit

Permalink
change global experimental check to be a side-effect import
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Aug 28, 2024
1 parent 1b3ba12 commit 6bf5eea
Show file tree
Hide file tree
Showing 147 changed files with 184 additions and 743 deletions.
6 changes: 1 addition & 5 deletions experimental/canisters/icrc/errors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

import { Record } from '../../../src/lib/experimental/candid/types/constructed/record';
import { nat } from '../../../src/lib/experimental/candid/types/primitive/nats/nat';
Expand Down
6 changes: 1 addition & 5 deletions experimental/canisters/icrc/icrc_1.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

import {
blob,
Expand Down
6 changes: 1 addition & 5 deletions experimental/canisters/icrc/icrc_2.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

import { blob } from '../../../src/lib/experimental/candid/types/constructed/blob';
import { Opt } from '../../../src/lib/experimental/candid/types/constructed/opt';
Expand Down
6 changes: 1 addition & 5 deletions experimental/canisters/icrc/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

import {
Canister,
Expand Down
6 changes: 1 addition & 5 deletions experimental/canisters/ledger/address/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../../src/lib/experimental/experimental';

import { Principal } from '@dfinity/principal';
import { getCrc32 } from '@dfinity/principal/lib/esm/utils/getCrc';
Expand Down
7 changes: 1 addition & 6 deletions experimental/canisters/ledger/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

// Some JS docs licensed under:
//
Expand All @@ -11,7 +7,6 @@ if (globalThis._azleExperimental !== true) {
// - https://github.com/dfinity/portal/blob/master/LICENSE
//
// Some documentation changed from original work.

import {
blob,
Canister,
Expand Down
7 changes: 1 addition & 6 deletions experimental/canisters/management/bitcoin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

// TODO I am thinking we should use the same names as ic-btc-types

import {
blob,
nat32,
Expand Down
7 changes: 1 addition & 6 deletions experimental/canisters/management/canister_info.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

// JS docs licensed under:
//
// - https://github.com/dfinity/cdk-rs/blob/main/LICENSE
//
// Some documentation changed from original work.

import { Opt } from '../../../src/lib/experimental/candid/types/constructed/opt';
import { Record } from '../../../src/lib/experimental/candid/types/constructed/record';
import { Variant } from '../../../src/lib/experimental/candid/types/constructed/variant';
Expand Down
6 changes: 1 addition & 5 deletions experimental/canisters/management/canister_management.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

import {
blob,
Expand Down
6 changes: 1 addition & 5 deletions experimental/canisters/management/http_request.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

import {
blob,
Expand Down
7 changes: 1 addition & 6 deletions experimental/canisters/management/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

// Some JS docs licensed under:
//
// - https://github.com/dfinity/cdk-rs/blob/main/LICENSE
//
// Some documentation changed from original work.

import { blob } from '../../../src/lib/experimental/candid/types/constructed/blob';
import { Vec } from '../../../src/lib/experimental/candid/types/constructed/vec';
import { Void } from '../../../src/lib/experimental/candid/types/primitive/void';
Expand Down
6 changes: 1 addition & 5 deletions experimental/canisters/management/t_ecdsa.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../src/lib/experimental/experimental';

import { blob } from '../../../src/lib/experimental/candid/types/constructed/blob';
import { Opt } from '../../../src/lib/experimental/candid/types/constructed/opt';
Expand Down
6 changes: 1 addition & 5 deletions experimental/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { experimentalMessage } from '../src/lib/experimental/experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../src/lib/experimental/experimental';

export * from '../src/lib/experimental';
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ let actor: ActorReloadJs | undefined;
const reloadedJsPath = process.argv[2];
const canisterId = process.argv[3];
const mainPath = process.argv[4];
const wasmedgeQuickJsPath = process.argv[5];
const esmAliases = JSON.parse(process.argv[6]);
const esmExternals = JSON.parse(process.argv[7]);
const canisterName = process.argv[8];
const postUpgradeIndex = Number(process.argv[9]);
const esmAliases = JSON.parse(process.argv[5]);
const esmExternals = JSON.parse(process.argv[6]);
const canisterName = process.argv[7];
const postUpgradeIndex = Number(process.argv[8]);

// TODO https://github.com/demergent-labs/azle/issues/1664
const watcher = watch([`**/*.ts`, `**/*.js`], {
Expand All @@ -44,12 +43,7 @@ watcher.on('all', async (event, path) => {

if (event === 'change') {
try {
await reloadJs(
actor,
reloadedJsPath,
mainPath,
wasmedgeQuickJsPath
);
await reloadJs(actor, reloadedJsPath, mainPath);
} catch (error) {
console.error(error);
}
Expand All @@ -59,12 +53,10 @@ watcher.on('all', async (event, path) => {
async function reloadJs(
actor: ActorReloadJs,
reloadedJsPath: string,
mainPath: string,
wasmedgeQuickJsPath: string
mainPath: string
): Promise<void> {
const javaScript = await compileJavaScript(
mainPath,
wasmedgeQuickJsPath,
esmAliases,
esmExternals
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { join } from 'path';

import { execSyncPretty } from '../../../../stable/utils/exec_sync_pretty';
import { AZLE_PACKAGE_PATH } from '../../../../stable/utils/global_paths';
import { WASMEDGE_QUICKJS_PATH } from '../../../utils/global_paths';

export function setupFileWatcher(
reloadedJsPath: string,
Expand Down Expand Up @@ -45,7 +44,6 @@ export function setupFileWatcher(
reloadedJsPath,
canisterId,
mainPath,
WASMEDGE_QUICKJS_PATH,
JSON.stringify(esmAliases),
JSON.stringify(esmExternals),
canisterName,
Expand Down
18 changes: 16 additions & 2 deletions src/build/stable/commands/compile/javascript.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { build, BuildOptions } from 'esbuild';
import esbuildPluginTsc from 'esbuild-plugin-tsc';

import { experimentalMessage } from '../../../../lib/experimental/experimental';

export async function compile(main: string): Promise<string> {
const prelude = getPrelude(main);
const buildOptions = getBuildOptions(prelude);
Expand Down Expand Up @@ -93,3 +91,19 @@ export function getBuildOptions(ts: string): BuildOptions {
]
};
}

function experimentalMessage(importName: string): string {
return `Azle: experimental mode must be enabled to import from ${importName}. You can enable experimental mode in your dfx.json file like this:
{
"canisters": {
"canisterName": {
"type": "azle",
"main": "index.ts",
"custom": {
"experimental": true
}
}
}
}
`;
}
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/candid_type.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../experimental';

import { IDL } from '@dfinity/candid';

Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../experimental';

export * from './candid_type';
export * from './manual';
Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/manual.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../experimental';

import { CandidType } from './candid_type';
import { AzleVoid } from './types/primitive/void';
Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/recursive.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../experimental';

import { IDL } from '@dfinity/candid';
import { v4 } from 'uuid';
Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/serde/decode.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../experimental';

import { IDL } from '@dfinity/candid';

Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/serde/encode.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../experimental';

import { IDL } from '@dfinity/candid';

Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/serde/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../experimental';

export { decode } from './decode';
export { encode } from './encode';
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/serde/visitors/decode_visitor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../experimental';

import { IDL } from '@dfinity/candid';

Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/serde/visitors/encode_visitor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../experimental';

import { IDL } from '@dfinity/candid';

Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/serde/visitors/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../experimental';

export { DecodeVisitor } from './decode_visitor';
export { EncodeVisitor } from './encode_visitor';
Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/serde/visitors/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../experimental';

/*
* The VisitorData gives us js_data which is the data that is about to be
Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/serde/visitors/visit/record.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../../experimental';

import { IDL } from '@dfinity/candid';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../../experimental';

import { IDL } from '@dfinity/candid';

Expand Down
6 changes: 1 addition & 5 deletions src/lib/experimental/candid/serde/visitors/visit/tuple.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../../experimental';

import { IDL } from '@dfinity/candid';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { experimentalMessage } from '../../../../../experimental';

if (globalThis._azleExperimental !== true) {
throw new Error(experimentalMessage('azle/experimental'));
}
import '../../../../../experimental';

import { IDL } from '@dfinity/candid';

Expand Down
Loading

0 comments on commit 6bf5eea

Please sign in to comment.