Node library (created in TS): Correct way to export avoiding duplicates - ready for publishing?
Can anyone help?
I just created a node library that I want to publish to npm - currently, I am testing it locally.
I have 2 directories that present models, these 2 directories have unique files but there are a few files where the name is the same i.e. meta-data.ts, requirements.ts - These files are automatically generated and although now these 2 files are the same across the 2 directories - they could diverge in the future.
My libraries are compiled to js and placed in a /dist directory and then in the root i am doing
export * "./models/red"
export * "./models/blue"
but this isn't possible as there are files the same.
the structure of the package that would be published would be
index.js
dist
models
red
..files
blue
..files
Now I can't really import them from the subdirectories on publishing because that means that in production I would have to import ( not in the same place)
import {MetaData} packagename/dist/models/red
import {MetaData} packagename/dist/models/blue
Hence I would need to include the dist folder in there and while developing locally this dist does not exist - and also the dist is the compiled files.
Also including the dist on the import just doesn't seem right
So I am wondering if I am doing this correctly and what my options are?
I thought I had to EXPORT all files from the root that I want my package to expose?
Also, there is no syntax for "exporting "as"
I don't want to rename my models, they should co-exist.
Of course, if I was importing the files locally without going through a package then I would not have this problem as i could import them relatively from the models
import {MetaData} ./models/red
import {MetaData} ./models/blue
node.js typescript npm
add a comment |
Can anyone help?
I just created a node library that I want to publish to npm - currently, I am testing it locally.
I have 2 directories that present models, these 2 directories have unique files but there are a few files where the name is the same i.e. meta-data.ts, requirements.ts - These files are automatically generated and although now these 2 files are the same across the 2 directories - they could diverge in the future.
My libraries are compiled to js and placed in a /dist directory and then in the root i am doing
export * "./models/red"
export * "./models/blue"
but this isn't possible as there are files the same.
the structure of the package that would be published would be
index.js
dist
models
red
..files
blue
..files
Now I can't really import them from the subdirectories on publishing because that means that in production I would have to import ( not in the same place)
import {MetaData} packagename/dist/models/red
import {MetaData} packagename/dist/models/blue
Hence I would need to include the dist folder in there and while developing locally this dist does not exist - and also the dist is the compiled files.
Also including the dist on the import just doesn't seem right
So I am wondering if I am doing this correctly and what my options are?
I thought I had to EXPORT all files from the root that I want my package to expose?
Also, there is no syntax for "exporting "as"
I don't want to rename my models, they should co-exist.
Of course, if I was importing the files locally without going through a package then I would not have this problem as i could import them relatively from the models
import {MetaData} ./models/red
import {MetaData} ./models/blue
node.js typescript npm
add a comment |
Can anyone help?
I just created a node library that I want to publish to npm - currently, I am testing it locally.
I have 2 directories that present models, these 2 directories have unique files but there are a few files where the name is the same i.e. meta-data.ts, requirements.ts - These files are automatically generated and although now these 2 files are the same across the 2 directories - they could diverge in the future.
My libraries are compiled to js and placed in a /dist directory and then in the root i am doing
export * "./models/red"
export * "./models/blue"
but this isn't possible as there are files the same.
the structure of the package that would be published would be
index.js
dist
models
red
..files
blue
..files
Now I can't really import them from the subdirectories on publishing because that means that in production I would have to import ( not in the same place)
import {MetaData} packagename/dist/models/red
import {MetaData} packagename/dist/models/blue
Hence I would need to include the dist folder in there and while developing locally this dist does not exist - and also the dist is the compiled files.
Also including the dist on the import just doesn't seem right
So I am wondering if I am doing this correctly and what my options are?
I thought I had to EXPORT all files from the root that I want my package to expose?
Also, there is no syntax for "exporting "as"
I don't want to rename my models, they should co-exist.
Of course, if I was importing the files locally without going through a package then I would not have this problem as i could import them relatively from the models
import {MetaData} ./models/red
import {MetaData} ./models/blue
node.js typescript npm
Can anyone help?
I just created a node library that I want to publish to npm - currently, I am testing it locally.
I have 2 directories that present models, these 2 directories have unique files but there are a few files where the name is the same i.e. meta-data.ts, requirements.ts - These files are automatically generated and although now these 2 files are the same across the 2 directories - they could diverge in the future.
My libraries are compiled to js and placed in a /dist directory and then in the root i am doing
export * "./models/red"
export * "./models/blue"
but this isn't possible as there are files the same.
the structure of the package that would be published would be
index.js
dist
models
red
..files
blue
..files
Now I can't really import them from the subdirectories on publishing because that means that in production I would have to import ( not in the same place)
import {MetaData} packagename/dist/models/red
import {MetaData} packagename/dist/models/blue
Hence I would need to include the dist folder in there and while developing locally this dist does not exist - and also the dist is the compiled files.
Also including the dist on the import just doesn't seem right
So I am wondering if I am doing this correctly and what my options are?
I thought I had to EXPORT all files from the root that I want my package to expose?
Also, there is no syntax for "exporting "as"
I don't want to rename my models, they should co-exist.
Of course, if I was importing the files locally without going through a package then I would not have this problem as i could import them relatively from the models
import {MetaData} ./models/red
import {MetaData} ./models/blue
node.js typescript npm
node.js typescript npm
asked Jan 2 at 7:44


Mark SmithMark Smith
2314
2314
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002849%2fnode-library-created-in-ts-correct-way-to-export-avoiding-duplicates-ready%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002849%2fnode-library-created-in-ts-correct-way-to-export-avoiding-duplicates-ready%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown