@designliquido/delegua-node 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +80 -80
  2. package/bin/delegua +2 -2
  3. package/bin/package.json +36 -36
  4. package/execucao.d.ts +1 -1
  5. package/execucao.js +42 -42
  6. package/fontes/delegua.d.ts +87 -86
  7. package/fontes/delegua.js +372 -371
  8. package/fontes/delegua.js.map +1 -1
  9. package/fontes/depuracao/index.d.ts +1 -1
  10. package/fontes/depuracao/index.js +17 -17
  11. package/fontes/depuracao/servidor-depuracao.d.ts +42 -42
  12. package/fontes/depuracao/servidor-depuracao.js +300 -300
  13. package/fontes/importador/importador.d.ts +27 -27
  14. package/fontes/importador/importador.js +90 -90
  15. package/fontes/importador/index.d.ts +2 -2
  16. package/fontes/importador/index.js +18 -18
  17. package/fontes/importador/retorno-importador.d.ts +9 -9
  18. package/fontes/importador/retorno-importador.js +2 -2
  19. package/fontes/interfaces/delegua-interface.d.ts +24 -24
  20. package/fontes/interfaces/delegua-interface.js +2 -2
  21. package/fontes/interfaces/importador-interface.d.ts +8 -8
  22. package/fontes/interfaces/importador-interface.js +2 -2
  23. package/fontes/interfaces/index.d.ts +2 -2
  24. package/fontes/interfaces/index.js +18 -18
  25. package/fontes/interpretador/dialetos/interpretador-visualg-com-depuracao-importacao.d.ts +14 -14
  26. package/fontes/interpretador/dialetos/interpretador-visualg-com-depuracao-importacao.js +76 -76
  27. package/fontes/interpretador/dialetos/interpretador-visualg-com-depuracao-importacao.js.map +1 -1
  28. package/fontes/interpretador/index.d.ts +1 -1
  29. package/fontes/interpretador/index.js +17 -17
  30. package/fontes/interpretador/interpretador-com-depuracao-importacao.d.ts +14 -14
  31. package/fontes/interpretador/interpretador-com-depuracao-importacao.js +76 -76
  32. package/fontes/interpretador/interpretador-com-depuracao-importacao.js.map +1 -1
  33. package/fontes/interpretador/interpretador.d.ts +18 -18
  34. package/fontes/interpretador/interpretador.js +80 -80
  35. package/fontes/interpretador/interpretador.js.map +1 -1
  36. package/fontes/interpretador/mecanismo-importacao-bibliotecas.d.ts +2 -2
  37. package/fontes/interpretador/mecanismo-importacao-bibliotecas.js +131 -131
  38. package/package.json +36 -36
@@ -1,132 +1,132 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const processoFilho = __importStar(require("node:child_process"));
27
- const caminho = __importStar(require("node:path"));
28
- const sistemaArquivos = __importStar(require("node:fs"));
29
- const excecoes_1 = require("@designliquido/delegua/fontes/excecoes");
30
- const funcao_padrao_1 = require("@designliquido/delegua/fontes/estruturas/funcao-padrao");
31
- const modulo_1 = require("@designliquido/delegua/fontes/estruturas/modulo");
32
- const classe_padrao_1 = require("@designliquido/delegua/fontes/estruturas/classe-padrao");
33
- const carregarBibliotecaDelegua = (nome) => {
34
- let dadosDoModulo;
35
- try {
36
- dadosDoModulo = require(nome);
37
- }
38
- catch (erro) {
39
- // Biblioteca não existe localmente. Tentar importação global
40
- try {
41
- dadosDoModulo = importarPacoteDeleguaCompleto(nome);
42
- }
43
- catch (erro2) {
44
- throw new excecoes_1.ErroEmTempoDeExecucao(null, `Biblioteca ${nome} não encontrada para importação.`);
45
- }
46
- }
47
- return modularizarBiblioteca(dadosDoModulo, nome);
48
- };
49
- const carregarBiblioteca = async (nomeDaBiblioteca, caminhoDaBiblioteca) => {
50
- let dadosDoModulo;
51
- try {
52
- dadosDoModulo = require(caminhoDaBiblioteca);
53
- }
54
- catch (erro) {
55
- try {
56
- dadosDoModulo = await importarPacoteExternoCompleto(nomeDaBiblioteca);
57
- }
58
- catch (erro2) {
59
- throw new excecoes_1.ErroEmTempoDeExecucao(null, `Biblioteca ${nomeDaBiblioteca} não encontrada para importação. Informações adicionais: ${(erro2 === null || erro2 === void 0 ? void 0 : erro2.message) || '(nenhuma)'}`);
60
- }
61
- }
62
- return modularizarBiblioteca(dadosDoModulo, nomeDaBiblioteca);
63
- };
64
- const modularizarBiblioteca = (dadosDoModulo, nome) => {
65
- const novoModulo = new modulo_1.DeleguaModulo(nome);
66
- const chaves = Object.keys(dadosDoModulo);
67
- for (let i = 0; i < chaves.length; i++) {
68
- const moduloAtual = dadosDoModulo[chaves[i]];
69
- if (typeof moduloAtual === 'function') {
70
- // Por definição, funções tradicionais e classes são identificadas em JavaScript como "functions".
71
- // A primeira heurística era verificando a propriedade `prototype`, mas isso não funciona bem
72
- // porque classes e funções avulsas todas possuem prototype.
73
- // Uma heurística nova é converter `moduloAtual` para `string` e verificar se a declaração começa com `class`.
74
- // Se sim, podemos dizer que a "function" é uma classe padrão.
75
- // Caso contrário, é uma função (`FuncaoPadrao`).
76
- if (String(moduloAtual).startsWith('class')) {
77
- const classePadrao = new classe_padrao_1.ClassePadrao(chaves[i], moduloAtual);
78
- novoModulo.componentes[chaves[i]] = classePadrao;
79
- }
80
- else {
81
- novoModulo.componentes[chaves[i]] = new funcao_padrao_1.FuncaoPadrao(moduloAtual.length, moduloAtual);
82
- }
83
- }
84
- else {
85
- novoModulo.componentes[chaves[i]] = moduloAtual;
86
- }
87
- }
88
- return novoModulo;
89
- };
90
- const importarPacoteCaminhoBase = async (caminhoRelativo) => {
91
- var _a;
92
- let resultado = null;
93
- const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
94
- const global = processoFilho.spawnSync(npm, ['root', '--location=global']);
95
- const caminhoAbsoluto = caminho.join(global.output[1].toString().trim()) + `\\${caminhoRelativo}\\package.json`;
96
- let arquivoInicio = JSON.parse(sistemaArquivos.readFileSync(caminhoAbsoluto, 'utf-8')).main || 'index.js';
97
- await (_a = caminho.join('file:///' + global.output[1].toString().trim()) +
98
- `\\${caminhoRelativo}\\${arquivoInicio.replace('./', '')}`, Promise.resolve().then(() => __importStar(require(_a)))).then((resposta) => {
99
- resultado = resposta;
100
- });
101
- return resultado;
102
- };
103
- const importarPacoteDeleguaCompleto = async (nome) => {
104
- return await importarPacoteCaminhoBase(`delegua\\node_modules\\${nome}`);
105
- };
106
- const importarPacoteExternoCompleto = async (nome) => {
107
- return await importarPacoteCaminhoBase(nome);
108
- };
109
- const verificarModulosDelegua = (nome) => {
110
- const modulos = {
111
- estatistica: '@designliquido/delegua-estatistica',
112
- estatística: '@designliquido/delegua-estatistica',
113
- fisica: '@designliquido/delegua-fisica',
114
- física: '@designliquido/delegua-fisica',
115
- json: '@designliquido/delegua-json',
116
- matematica: '@designliquido/delegua-matematica',
117
- matemática: '@designliquido/delegua-matematica',
118
- tempo: '@designliquido/delegua-tempo',
119
- };
120
- if (Object.keys(modulos).includes(nome)) {
121
- return modulos[nome].toString();
122
- }
123
- return false;
124
- };
125
- async function default_1(nome) {
126
- const nomeBibliotecaResolvido = verificarModulosDelegua(nome);
127
- return nomeBibliotecaResolvido
128
- ? carregarBibliotecaDelegua(String(nomeBibliotecaResolvido))
129
- : await carregarBiblioteca(nome, nome);
130
- }
131
- exports.default = default_1;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const processoFilho = __importStar(require("node:child_process"));
27
+ const caminho = __importStar(require("node:path"));
28
+ const sistemaArquivos = __importStar(require("node:fs"));
29
+ const excecoes_1 = require("@designliquido/delegua/fontes/excecoes");
30
+ const funcao_padrao_1 = require("@designliquido/delegua/fontes/estruturas/funcao-padrao");
31
+ const modulo_1 = require("@designliquido/delegua/fontes/estruturas/modulo");
32
+ const classe_padrao_1 = require("@designliquido/delegua/fontes/estruturas/classe-padrao");
33
+ const carregarBibliotecaDelegua = (nome) => {
34
+ let dadosDoModulo;
35
+ try {
36
+ dadosDoModulo = require(nome);
37
+ }
38
+ catch (erro) {
39
+ // Biblioteca não existe localmente. Tentar importação global
40
+ try {
41
+ dadosDoModulo = importarPacoteDeleguaCompleto(nome);
42
+ }
43
+ catch (erro2) {
44
+ throw new excecoes_1.ErroEmTempoDeExecucao(null, `Biblioteca ${nome} não encontrada para importação.`);
45
+ }
46
+ }
47
+ return modularizarBiblioteca(dadosDoModulo, nome);
48
+ };
49
+ const carregarBiblioteca = async (nomeDaBiblioteca, caminhoDaBiblioteca) => {
50
+ let dadosDoModulo;
51
+ try {
52
+ dadosDoModulo = require(caminhoDaBiblioteca);
53
+ }
54
+ catch (erro) {
55
+ try {
56
+ dadosDoModulo = await importarPacoteExternoCompleto(nomeDaBiblioteca);
57
+ }
58
+ catch (erro2) {
59
+ throw new excecoes_1.ErroEmTempoDeExecucao(null, `Biblioteca ${nomeDaBiblioteca} não encontrada para importação. Informações adicionais: ${(erro2 === null || erro2 === void 0 ? void 0 : erro2.message) || '(nenhuma)'}`);
60
+ }
61
+ }
62
+ return modularizarBiblioteca(dadosDoModulo, nomeDaBiblioteca);
63
+ };
64
+ const modularizarBiblioteca = (dadosDoModulo, nome) => {
65
+ const novoModulo = new modulo_1.DeleguaModulo(nome);
66
+ const chaves = Object.keys(dadosDoModulo);
67
+ for (let i = 0; i < chaves.length; i++) {
68
+ const moduloAtual = dadosDoModulo[chaves[i]];
69
+ if (typeof moduloAtual === 'function') {
70
+ // Por definição, funções tradicionais e classes são identificadas em JavaScript como "functions".
71
+ // A primeira heurística era verificando a propriedade `prototype`, mas isso não funciona bem
72
+ // porque classes e funções avulsas todas possuem prototype.
73
+ // Uma heurística nova é converter `moduloAtual` para `string` e verificar se a declaração começa com `class`.
74
+ // Se sim, podemos dizer que a "function" é uma classe padrão.
75
+ // Caso contrário, é uma função (`FuncaoPadrao`).
76
+ if (String(moduloAtual).startsWith('class')) {
77
+ const classePadrao = new classe_padrao_1.ClassePadrao(chaves[i], moduloAtual);
78
+ novoModulo.componentes[chaves[i]] = classePadrao;
79
+ }
80
+ else {
81
+ novoModulo.componentes[chaves[i]] = new funcao_padrao_1.FuncaoPadrao(moduloAtual.length, moduloAtual);
82
+ }
83
+ }
84
+ else {
85
+ novoModulo.componentes[chaves[i]] = moduloAtual;
86
+ }
87
+ }
88
+ return novoModulo;
89
+ };
90
+ const importarPacoteCaminhoBase = async (caminhoRelativo) => {
91
+ var _a;
92
+ let resultado = null;
93
+ const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
94
+ const global = processoFilho.spawnSync(npm, ['root', '--location=global']);
95
+ const caminhoAbsoluto = caminho.join(global.output[1].toString().trim()) + `\\${caminhoRelativo}\\package.json`;
96
+ let arquivoInicio = JSON.parse(sistemaArquivos.readFileSync(caminhoAbsoluto, 'utf-8')).main || 'index.js';
97
+ await (_a = caminho.join('file:///' + global.output[1].toString().trim()) +
98
+ `\\${caminhoRelativo}\\${arquivoInicio.replace('./', '')}`, Promise.resolve().then(() => __importStar(require(_a)))).then((resposta) => {
99
+ resultado = resposta;
100
+ });
101
+ return resultado;
102
+ };
103
+ const importarPacoteDeleguaCompleto = async (nome) => {
104
+ return await importarPacoteCaminhoBase(`delegua\\node_modules\\${nome}`);
105
+ };
106
+ const importarPacoteExternoCompleto = async (nome) => {
107
+ return await importarPacoteCaminhoBase(nome);
108
+ };
109
+ const verificarModulosDelegua = (nome) => {
110
+ const modulos = {
111
+ estatistica: '@designliquido/delegua-estatistica',
112
+ estatística: '@designliquido/delegua-estatistica',
113
+ fisica: '@designliquido/delegua-fisica',
114
+ física: '@designliquido/delegua-fisica',
115
+ json: '@designliquido/delegua-json',
116
+ matematica: '@designliquido/delegua-matematica',
117
+ matemática: '@designliquido/delegua-matematica',
118
+ tempo: '@designliquido/delegua-tempo',
119
+ };
120
+ if (Object.keys(modulos).includes(nome)) {
121
+ return modulos[nome].toString();
122
+ }
123
+ return false;
124
+ };
125
+ async function default_1(nome) {
126
+ const nomeBibliotecaResolvido = verificarModulosDelegua(nome);
127
+ return nomeBibliotecaResolvido
128
+ ? carregarBibliotecaDelegua(String(nomeBibliotecaResolvido))
129
+ : await carregarBiblioteca(nome, nome);
130
+ }
131
+ exports.default = default_1;
132
132
  //# sourceMappingURL=mecanismo-importacao-bibliotecas.js.map
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "@designliquido/delegua-node",
3
- "version": "0.10.0",
4
- "description": "Linguagem Delégua com capacidades para ecossistema Node.js.",
5
- "scripts": {
6
- "empacotar": "rimraf ./dist && tsc && copyfiles -V ./bin/delegua ./bin/delegua.cmd ./dist && copyfiles -V ./package.json ./dist/bin && copyfiles -V ./README.md ./dist",
7
- "testes-unitarios": "jest --coverage",
8
- "testes:egua": "./bin/delegua-ts exemplos/dialetos/egua-classico/testes.egua",
9
- "testes:delegua:bhaskara": "./bin/delegua-ts exemplos/dialetos/egua-classico/bhaskara.egua",
10
- "testes:delegua:fibonacci": "./bin/delegua-ts exemplos/dialetos/egua-classico/fibonacci.egua",
11
- "testes:egua-classico": "./bin/delegua-ts --dialeto egua exemplos/dialetos/egua-classico/testes.egua",
12
- "testes:servidor-depuracao": "ts-node ./fontes/depuracao/servidor-depuracao.ts"
13
- },
14
- "dependencies": {
15
- "@designliquido/delegua": "^0.15.1",
16
- "chalk": "4.1.2",
17
- "commander": "^9.4.1"
18
- },
19
- "devDependencies": {
20
- "@designliquido/delegua-estatistica": "^0.0.5",
21
- "@designliquido/delegua-fisica": "^0.0.2",
22
- "@designliquido/delegua-json": "^0.0.0",
23
- "@designliquido/delegua-matematica": "^0.2.0",
24
- "@designliquido/delegua-tempo": "^0.0.1",
25
- "@types/estree": "^1.0.0",
26
- "@types/jest": "^29.4.0",
27
- "@types/node": "^18.11.19",
28
- "copyfiles": "^2.4.1",
29
- "jest": "^29.4.1",
30
- "release-it": "^15.6.0",
31
- "rimraf": "^4.1.2",
32
- "ts-jest": "^29.0.5",
33
- "ts-node": "^10.9.1",
34
- "typescript": "^4.9.5"
35
- }
36
- }
1
+ {
2
+ "name": "@designliquido/delegua-node",
3
+ "version": "0.12.0",
4
+ "description": "Linguagem Delégua com capacidades para ecossistema Node.js.",
5
+ "scripts": {
6
+ "empacotar": "rimraf ./dist && tsc && copyfiles -V ./bin/delegua ./bin/delegua.cmd ./dist && copyfiles -V ./package.json ./dist/bin && copyfiles -V ./README.md ./dist",
7
+ "testes-unitarios": "jest --coverage",
8
+ "testes:egua": "./bin/delegua-ts exemplos/dialetos/egua-classico/testes.egua",
9
+ "testes:delegua:bhaskara": "./bin/delegua-ts exemplos/dialetos/egua-classico/bhaskara.egua",
10
+ "testes:delegua:fibonacci": "./bin/delegua-ts exemplos/dialetos/egua-classico/fibonacci.egua",
11
+ "testes:egua-classico": "./bin/delegua-ts --dialeto egua exemplos/dialetos/egua-classico/testes.egua",
12
+ "testes:servidor-depuracao": "ts-node ./fontes/depuracao/servidor-depuracao.ts"
13
+ },
14
+ "dependencies": {
15
+ "@designliquido/delegua": "^0.15.3",
16
+ "chalk": "4.1.2",
17
+ "commander": "^9.4.1"
18
+ },
19
+ "devDependencies": {
20
+ "@designliquido/delegua-estatistica": "^0.0.5",
21
+ "@designliquido/delegua-fisica": "^0.0.2",
22
+ "@designliquido/delegua-json": "^0.0.0",
23
+ "@designliquido/delegua-matematica": "^0.2.0",
24
+ "@designliquido/delegua-tempo": "^0.0.1",
25
+ "@types/estree": "^1.0.0",
26
+ "@types/jest": "^29.4.0",
27
+ "@types/node": "^18.11.19",
28
+ "copyfiles": "^2.4.1",
29
+ "jest": "^29.4.1",
30
+ "release-it": "^15.6.0",
31
+ "rimraf": "^4.1.2",
32
+ "ts-jest": "^29.0.5",
33
+ "ts-node": "^10.9.1",
34
+ "typescript": "^4.9.5"
35
+ }
36
+ }